Skip to content

Commit

Permalink
Use link fields custom text and element titles for the search index. …
Browse files Browse the repository at this point in the history
…Bump to 2.5.0
  • Loading branch information
mmikkel committed Oct 18, 2023
1 parent 77a3358 commit b23e37f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 24 additions & 1 deletion src/fields/LinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -456,4 +456,27 @@ public function getTableAttributeHtml(mixed $value, ElementInterface $element):
$label = StringHelper::truncate($url, 50);
return "<a href=\"$url\" target=\"_blank\" class=\"go\">$label</a>";
}

/**
* @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
}

}

0 comments on commit b23e37f

Please sign in to comment.