mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 07:47:00 +02:00
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".
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user