From 5e91b745e11762e5986fd707958bad3617835995 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 1 Nov 2024 09:12:36 -0400 Subject: [PATCH] Add hookable method in ProcessPageSearchLive to enable overriding what gets searched in the admin search box at runtime. This is also useful if you want to search fields that the interactive module configuration may not let you configure, such as "field.property". --- .../ProcessPageSearchLive.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php b/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php index 5c9f59d2..1fecb7da 100644 --- a/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php +++ b/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php @@ -7,6 +7,7 @@ * @method renderItem(array $item, $prefix = 'pw-search', $class = 'list') * @method string|array execute($getJSON = true) * @method bool findCustom(array $data) + * @method array getDefaultPageSearchFields() * * @todo support searching repeaters * @@ -380,7 +381,7 @@ class ProcessPageSearchLive extends Wire { $selectors[] = $property . $operator . $value; } else { // we did not recognize the property, so use field(s) defined in module instead - $selectors[] = implode('|', $this->defaultPageSearchFields) . $operator . $value; + $selectors[] = implode('|', $this->getDefaultPageSearchFields()) . $operator . $value; } $help = strtolower($q) === 'help'; @@ -1326,4 +1327,26 @@ class ProcessPageSearchLive extends Wire { return true; } + /** + * Get the names of fields that should be used when searching pages + * + * Hook this from /site/templates/admin.php to modify what gets searched. + * This overrides the setting specified interactively in the ProcessPageSearch module settings. + * + * ~~~~~ + * $wire->addHookAfter('ProcessPageSearchLive::getDefaultPageSearchFields', function(HookEvent $e) { + * $e->return = [ 'title', 'subtitle', 'categories.title' ]; + * }); + * ~~~~~ + * + * #pw-hooker + * + * @return array + * @since 3.0.242 + * + */ + public function ___getDefaultPageSearchFields() { + return $this->defaultPageSearchFields; + } + }