Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hibberd committed Aug 22, 2018
1 parent e05615c commit 48a2248
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 22 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
* Changed - Improved Linked In link validation
* Changed - Improved url link validation
* Changed - Element link types now allowed to select disabled elements to match the first party Craft element fieldtypes

* Changed - Updated element select to match first party fields

### Added

* Added `isElementLink()` check to link models to quickly determine if the link is an element type
* Added `isAvailable()` check to link models to quickly determine if the link is an element type
* Added setting to override the default placeholder text for basic and social link types
* Added `getTableAttributeHtmlLink()` Linkit fields are now previewable table colums in table view
* Added status indicators to preview to determine if a link is available
* Added plugin setting to configure how you handle disabled element types

### Fixed

* Linkit fields are now previewable table colums in table view #32
* Fixed issue with the Craft 2 normailize function when a type is not specified
* Fixed issue
* Fixed cp translation bug on element link types when using multiple sites


## 1.1.0 - 2018-04-24


## 1.0.8 - 2018-04-24
Expand Down
4 changes: 2 additions & 2 deletions src/base/ElementLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public static function elementType()

public static function settingsTemplatePath(): string
{
return 'linkit/types/settings/_element';
return 'linkit/types/settings/element';
}

public static function inputTemplatePath(): string
{
return 'linkit/types/input/_element';
return 'linkit/types/input/element';
}

// Public
Expand Down
26 changes: 21 additions & 5 deletions src/base/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public static function defaultPlaceholder(): string

public static function settingsTemplatePath(): string
{
return 'linkit/types/settings/_default';
return 'linkit/types/settings/text';
}

public static function inputTemplatePath(): string
{
return 'linkit/types/input/_default';
return 'linkit/types/input/text';
}

public static function hasSettings(): bool
Expand All @@ -66,6 +66,7 @@ public static function isElementLink(): bool
public $ownerElement;

public $customLabel;
public $customPlaceholder;

public $fieldSettings;
public $value;
Expand Down Expand Up @@ -110,6 +111,15 @@ public function getSelectionLabel(): string
return $this->defaultSelectionLabel();
}

public function getPlaceholder(): string
{
if(!is_null($this->customPlaceholder) && $this->customPlaceholder != '')
{
return $this->customPlaceholder;
}
return static::defaultPlaceholder();
}

public function getSettingsHtml(): string
{
return Craft::$app->getView()->renderTemplate(
Expand All @@ -120,7 +130,7 @@ public function getSettingsHtml(): string
);
}

public function getInputHtml(string $name, Link $currentLink = null, ElementInterface $element = null): string
public function getInputHtml(string $name, $field, Link $currentLink = null, ElementInterface $element = null): string
{
return Craft::$app->getView()->renderTemplate(
static::inputTemplatePath(),
Expand All @@ -129,13 +139,14 @@ public function getInputHtml(string $name, Link $currentLink = null, ElementInte
'link' => $this,
'currentLink' => $currentLink,
'element' => $element,
'field' => $field,
]
);
}

public function getLink($customAttributes = [], $raw = true)
public function getLink($customAttributes = [], $raw = true, $preview = false)
{
if(!$this->isAvailable())
if(!$preview && !$this->isAvailable())
{
return '';
}
Expand All @@ -144,6 +155,11 @@ public function getLink($customAttributes = [], $raw = true)
return $raw ? TemplateHelper::raw($html) : $html;
}

public function getLinkPreview($customAttributes = [])
{
return $this->getLink($customAttributes, false, true);
}

public function getUrl(): string
{
return (string) $this->value;
Expand Down
2 changes: 1 addition & 1 deletion src/base/LinkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function defaultSelectionLabel(): string;
public function getLabel(): string;
public function getSelectionLabel(): string;

public function getInputHtml(string $name, Link $currentLink = null): string;
public function getInputHtml(string $name, $field, Link $currentLink = null): string;
public function getSettingsHtml(): string;

public function getType(): string;
Expand Down
4 changes: 1 addition & 3 deletions src/fields/LinkitField.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ public function getTableAttributeHtml($value, ElementInterface $element): string
{
if($value instanceof Link)
{
return $value->getLink([
// 'title' => 'Some custom title here'
], false) ?? '';
return '<span title="Link '.($value->isAvailable() ? 'Enabled' : 'Disabled').'" class="status '.($value->isAvailable() ? 'enabled' : 'disabled').'"></span>'.$value->getLinkPreview();
}
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function elementType()

public static function settingsTemplatePath(): string
{
return 'linkit/types/settings/_user';
return 'linkit/types/settings/user';
}

public static function defaultUserPath(): string
Expand Down
2 changes: 1 addition & 1 deletion src/templates/fields/_input.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{% set isCurrentType = currentLink and currentLink.type == linkType.type %}

<div id="{{ name }}-{{ linkType.type|id }}" class="linkit--{{ linkType.defaultLabel|lower }} {{ not singleLinkType and not isCurrentType ? 'hidden' }}">
{{ linkType.getInputHtml(name, (isCurrentType ? currentLink : null), (element ?? null))|raw }}
{{ linkType.getInputHtml(name, field, (isCurrentType ? currentLink : null), (element ?? null))|raw }}
</div>

{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
name: name ~ '[values]['~ link.type ~']',
elementType: link.elementType(),
selectionLabel: link.selectionLabel,
sources: link.sources == '*' ? null : link.sources,
sources: link.sources ?? '*',
sourceElementId: element.id,
limit: 1,
elements: (currentLink.element ?? false) ? [currentLink.element] : [],
criteria: {
enabledForSite: null,
siteId: element.siteId ?? null,
status: null,
enabledForSite: false
}
},
storageKey: 'field.'~field.id,
}) }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
id: name ~ link.type|id ~ '-value',
name: name ~ '[values]['~ link.type ~']',
value: currentLink.value ?? '',
placeholder: link.defaultPlaceholder,
placeholder: link.placeholder,
}) }}

File renamed without changes.
13 changes: 13 additions & 0 deletions src/templates/types/settings/text.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% import "_includes/forms" as forms %}

{% include 'linkit/types/settings/_default' %}

{{ forms.textField({
label: "Placeholder"|t('linkit'),
instructions: "Override the default placeholder"|t('linkit'),
id: type.type|id~'-customPlaceholder',
name: 'customPlaceholder',
value: type.customPlaceholder ?? '',
placeholder: type.defaultPlaceholder,
errors: type.getErrors('customPlaceholder')
}) }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% import "_includes/forms" as forms %}

{% include 'linkit/types/settings/_element' %}
{% include 'linkit/types/settings/element' %}

{{ forms.textField({
label: "User Path"|t('linkit'),
Expand Down

0 comments on commit 48a2248

Please sign in to comment.