Prefixing search filters for the React search form context

This commit is contained in:
Guy Marriott 2018-10-01 13:38:32 +13:00
parent c54e7317d2
commit c503dbd634
No known key found for this signature in database
GPG Key ID: A80F9ACCB86D3DA7

View File

@ -235,11 +235,19 @@ class GridFieldFilterHeader implements GridField_URLHandler, GridField_HTMLProvi
$name = $gridField->Title ?: singleton($gridField->getModelClass())->i18n_plural_name();
// Prefix "Search__" onto the filters for the React component
$filters = $context->getSearchParams();
if (!$this->useLegacyFilterHeader && !empty($filters)) {
$filters = array_combine(array_map(function ($key) {
return 'Search__' . $key;
}, array_keys($filters)), $filters);
}
$schema = [
'formSchemaUrl' => $schemaUrl,
'name' => $searchField,
'placeholder' => _t(__CLASS__ . '.Search', 'Search "{name}"', ['name' => $name]),
'filters' => $context->getSearchParams() ?: new \stdClass, // stdClass maps to empty json object '{}'
'filters' => $filters ?: new \stdClass, // stdClass maps to empty json object '{}'
'gridfield' => $gridField->getName(),
'searchAction' => GridField_FormAction::create($gridField, 'filter', false, 'filter', null)->getAttribute('name'),
'clearAction' => GridField_FormAction::create($gridField, 'reset', false, 'reset', null)->getAttribute('name')
@ -294,6 +302,7 @@ class GridFieldFilterHeader implements GridField_URLHandler, GridField_HTMLProvi
$searchFields,
new FieldList()
);
$form->setFormMethod('get');
$form->setFormAction($gridField->Link());
$form->addExtraClass('cms-search-form form--no-dividers');