diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 441b055..ec9f38d 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,5 +1,9 @@ # Release Notes for LinkMate +## 2.5.0 - 2023-10-19 +### Added +- Link fields' custom text and linked element titles will now be added to Craft's search index, provided the field has the "Use this field’s values as search keywords" field setting enabled. + ## 2.4.1 - 2023-04-04 ### Fixed - Fixes a multi-site issue due to `Element::displayName()` being translated under the hood. diff --git a/composer.json b/composer.json index 214d24f..bd067ee 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "vaersaagod/linkmate", "description": "Let's hook you up, mate!", "type": "craft-plugin", - "version": "2.4.1", + "version": "2.5.0", "keywords": [ "craft", "cms", diff --git a/src/fields/LinkField.php b/src/fields/LinkField.php index 048467c..3113827 100644 --- a/src/fields/LinkField.php +++ b/src/fields/LinkField.php @@ -8,9 +8,9 @@ use craft\base\PreviewableFieldInterface; use craft\helpers\Html; use craft\helpers\Json; - use craft\helpers\StringHelper; use craft\helpers\UrlHelper; + use vaersaagod\linkmate\helpers\MigrateHelper; use vaersaagod\linkmate\LinkMate; use vaersaagod\linkmate\models\Link; @@ -456,4 +456,27 @@ public function getTableAttributeHtml(mixed $value, ElementInterface $element): $label = StringHelper::truncate($url, 50); return "$label"; } + + /** + * @param mixed $value + * @param ElementInterface $element + * @return string + */ + public function getSearchKeywords(mixed $value, ElementInterface $element): string + { + if (!$value instanceof Link) { + return ''; + } + $keywords = []; + if (!empty($value->customText) && $value->getAllowCustomText()) { + $keywords[] = $value->customText; + } + /** @var ElementInterface|null $element */ + $element = $value->getElement(true); + if ($element && $element::hasTitles() && !empty($element->title)) { + $keywords[] = $element->title; + } + return parent::getSearchKeywords($keywords, $element); // TODO: Change the autogenerated stub + } + }