From 48a224852dae565b839b1262dc434d22b432a4c4 Mon Sep 17 00:00:00 2001 From: Sam Hibberd Date: Wed, 22 Aug 2018 17:06:01 +0100 Subject: [PATCH] Bug Fixes --- CHANGELOG.md | 12 ++++++--- src/base/ElementLink.php | 4 +-- src/base/Link.php | 26 +++++++++++++++---- src/base/LinkInterface.php | 2 +- src/fields/LinkitField.php | 4 +-- src/models/User.php | 2 +- src/templates/fields/_input.twig | 2 +- .../input/{_element.twig => element.twig} | 9 ++++--- .../types/input/{_default.twig => text.twig} | 2 +- .../settings/{_element.twig => element.twig} | 0 src/templates/types/settings/text.twig | 13 ++++++++++ .../types/settings/{_user.twig => user.twig} | 2 +- 12 files changed, 56 insertions(+), 22 deletions(-) rename src/templates/types/input/{_element.twig => element.twig} (73%) rename src/templates/types/input/{_default.twig => text.twig} (81%) rename src/templates/types/settings/{_element.twig => element.twig} (100%) create mode 100644 src/templates/types/settings/text.twig rename src/templates/types/settings/{_user.twig => user.twig} (90%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 694339e..04d4e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/base/ElementLink.php b/src/base/ElementLink.php index e358e9e..b54aaea 100644 --- a/src/base/ElementLink.php +++ b/src/base/ElementLink.php @@ -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 diff --git a/src/base/Link.php b/src/base/Link.php index 5f819ff..de6f426 100644 --- a/src/base/Link.php +++ b/src/base/Link.php @@ -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 @@ -66,6 +66,7 @@ public static function isElementLink(): bool public $ownerElement; public $customLabel; + public $customPlaceholder; public $fieldSettings; public $value; @@ -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( @@ -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(), @@ -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 ''; } @@ -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; diff --git a/src/base/LinkInterface.php b/src/base/LinkInterface.php index 987973c..975ba96 100644 --- a/src/base/LinkInterface.php +++ b/src/base/LinkInterface.php @@ -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; diff --git a/src/fields/LinkitField.php b/src/fields/LinkitField.php index 3d00e55..021e534 100644 --- a/src/fields/LinkitField.php +++ b/src/fields/LinkitField.php @@ -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 ''.$value->getLinkPreview(); } return ''; } diff --git a/src/models/User.php b/src/models/User.php index fa2e42a..ca6e844 100644 --- a/src/models/User.php +++ b/src/models/User.php @@ -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 diff --git a/src/templates/fields/_input.twig b/src/templates/fields/_input.twig index 7455ba7..3d69e1b 100644 --- a/src/templates/fields/_input.twig +++ b/src/templates/fields/_input.twig @@ -35,7 +35,7 @@ {% set isCurrentType = currentLink and currentLink.type == linkType.type %}
- {{ linkType.getInputHtml(name, (isCurrentType ? currentLink : null), (element ?? null))|raw }} + {{ linkType.getInputHtml(name, field, (isCurrentType ? currentLink : null), (element ?? null))|raw }}
{% endfor %} diff --git a/src/templates/types/input/_element.twig b/src/templates/types/input/element.twig similarity index 73% rename from src/templates/types/input/_element.twig rename to src/templates/types/input/element.twig index 7d0b38a..9f24341 100644 --- a/src/templates/types/input/_element.twig +++ b/src/templates/types/input/element.twig @@ -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, }) }} diff --git a/src/templates/types/input/_default.twig b/src/templates/types/input/text.twig similarity index 81% rename from src/templates/types/input/_default.twig rename to src/templates/types/input/text.twig index 4244e4d..5aa865d 100644 --- a/src/templates/types/input/_default.twig +++ b/src/templates/types/input/text.twig @@ -4,6 +4,6 @@ id: name ~ link.type|id ~ '-value', name: name ~ '[values]['~ link.type ~']', value: currentLink.value ?? '', - placeholder: link.defaultPlaceholder, + placeholder: link.placeholder, }) }} diff --git a/src/templates/types/settings/_element.twig b/src/templates/types/settings/element.twig similarity index 100% rename from src/templates/types/settings/_element.twig rename to src/templates/types/settings/element.twig diff --git a/src/templates/types/settings/text.twig b/src/templates/types/settings/text.twig new file mode 100644 index 0000000..cb4c0cd --- /dev/null +++ b/src/templates/types/settings/text.twig @@ -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') +}) }} diff --git a/src/templates/types/settings/_user.twig b/src/templates/types/settings/user.twig similarity index 90% rename from src/templates/types/settings/_user.twig rename to src/templates/types/settings/user.twig index 576c52c..0a94c18 100644 --- a/src/templates/types/settings/_user.twig +++ b/src/templates/types/settings/user.twig @@ -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'),