Skip to content

Commit 3177769

Browse files
committed
Include option labels in search keywords
Resolves #9799
1 parent 1913c22 commit 3177769

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
### Changed
6+
- 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))
67
- 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.
78
- `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.
89
- `craft\services\Elements::duplicateElement()` now has a `$placeInStructure` argument.

src/fields/BaseOptionsField.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,30 @@ public function serializeValue($value, ElementInterface $element = null)
309309
return parent::serializeValue($value, $element);
310310
}
311311

312+
/**
313+
* @inheritdoc
314+
*/
315+
protected function searchKeywords($value, ElementInterface $element): string
316+
{
317+
$keywords = [];
318+
319+
if ($this->multi) {
320+
/** @var MultiOptionsFieldData|OptionData[] $value */
321+
foreach ($value as $option) {
322+
$keywords[] = $option->value;
323+
$keywords[] = $option->label;
324+
}
325+
} else {
326+
/** @var SingleOptionFieldData $value */
327+
if ($value->value !== null) {
328+
$keywords[] = $value->value;
329+
$keywords[] = $value->label;
330+
}
331+
}
332+
333+
return implode(' ', $keywords);
334+
}
335+
312336
/**
313337
* @inheritdoc
314338
* @since 3.4.6

0 commit comments

Comments
 (0)