From c503dbd63433eccffb860b2c323804d56f2f6032 Mon Sep 17 00:00:00 2001 From: Guy Marriott Date: Mon, 1 Oct 2018 13:38:32 +1300 Subject: [PATCH] Prefixing search filters for the React search form context --- src/Forms/GridField/GridFieldFilterHeader.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Forms/GridField/GridFieldFilterHeader.php b/src/Forms/GridField/GridFieldFilterHeader.php index b70c28ec3..207c3f633 100755 --- a/src/Forms/GridField/GridFieldFilterHeader.php +++ b/src/Forms/GridField/GridFieldFilterHeader.php @@ -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');