Skip to content

Commit

Permalink
Include option labels in search keywords
Browse files Browse the repository at this point in the history
Resolves #9799
  • Loading branch information
brandonkelly committed Sep 7, 2021
1 parent 1913c22 commit 3177769
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

### Changed
- Checkboxes, Dropdown, Multi-select, and Radio Buttons fields now include the selected options’ labels in their search keywords. ([#9799](https://github.com/craftcms/cms/issues/9799))
- It’s now possible for field types to disable delta name registration for nested custom fields by calling `Craft::$app->view->setIsDeltaRegistrationActive(false);` before rendering them.
- `craft\models\FieldLayout::createForm()` now accepts a `registerDeltas` key in its `$config` argument, which can be set to `true` or `false` to enable/disable delta name registration for any custom fields in the form.
- `craft\services\Elements::duplicateElement()` now has a `$placeInStructure` argument.
Expand Down
24 changes: 24 additions & 0 deletions src/fields/BaseOptionsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,30 @@ public function serializeValue($value, ElementInterface $element = null)
return parent::serializeValue($value, $element);
}

/**
* @inheritdoc
*/
protected function searchKeywords($value, ElementInterface $element): string
{
$keywords = [];

if ($this->multi) {
/** @var MultiOptionsFieldData|OptionData[] $value */
foreach ($value as $option) {
$keywords[] = $option->value;
$keywords[] = $option->label;
}
} else {
/** @var SingleOptionFieldData $value */
if ($value->value !== null) {
$keywords[] = $value->value;
$keywords[] = $value->label;
}
}

return implode(' ', $keywords);
}

/**
* @inheritdoc
* @since 3.4.6
Expand Down

0 comments on commit 3177769

Please sign in to comment.