Add config to force legacy filter header globally

This commit is contained in:
Luke Edwards 2018-10-26 14:28:15 +13:00
parent b47d9abd7c
commit d879148bff
2 changed files with 19 additions and 2 deletions

View File

@ -26,6 +26,12 @@ To enable the legacy search API on a `GridFieldFilterHeader`, you can either:
* set the `useLegacyFilterHeader` property to `true`,
* or pass `true` to the first argument of its constructor.
To force the legacy search API on all instances of `GridFieldFilterHeader`, you can set it in your [configuration file](../../configuration):
```yml
SilverStripe\Forms\GridField\GridFieldFilterHeader:
force_legacy: true
```
```php
public function getCMSFields()
{

View File

@ -6,6 +6,7 @@ use LogicException;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\FieldGroup;
@ -43,6 +44,16 @@ class GridFieldFilterHeader implements GridField_URLHandler, GridField_HTMLProvi
*/
public $useLegacyFilterHeader = false;
/**
* Forces all filter components to revert to displaying the legacy
* table header style rather than the react driven search box
*
* @deprecated 4.3.0:5.0.0 Will be removed in 5.0
* @config
* @var bool
*/
private static $force_legacy = false;
/**
* @var \SilverStripe\ORM\Search\SearchContext
*/
@ -76,7 +87,7 @@ class GridFieldFilterHeader implements GridField_URLHandler, GridField_HTMLProvi
}
/**
* @param bool $useLegacy
* @param bool $useLegacy This will be removed in 5.0
* @param callable|null $updateSearchContext This will be removed in 5.0
* @param callable|null $updateSearchForm This will be removed in 5.0
*/
@ -85,7 +96,7 @@ class GridFieldFilterHeader implements GridField_URLHandler, GridField_HTMLProvi
callable $updateSearchContext = null,
callable $updateSearchForm = null
) {
$this->useLegacyFilterHeader = $useLegacy;
$this->useLegacyFilterHeader = Config::inst()->get(self::class, 'force_legacy') || $useLegacy;
$this->updateSearchContextCallback = $updateSearchContext;
$this->updateSearchFormCallback = $updateSearchForm;
}