From cc674cec9b8208924fcca4f25a2c237b4129b07f Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Thu, 14 Mar 2019 11:12:28 +1300 Subject: [PATCH] SS 4.3 upgrade. --- composer.json | 4 +- src/Form/GridField/RichFilterHeader.php | 59 ++++++++----------------- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index f740092..92f08f7 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ }, "require": { "silverstripe/vendor-plugin": "^1.0", - "silverstripe/framework": "^4@dev", - "silverstripe/cms": "^4@dev" + "silverstripe/framework": "^4.3", + "silverstripe/cms": "^4.3" }, "require-dev": { "phpunit/phpunit": "^5.7" diff --git a/src/Form/GridField/RichFilterHeader.php b/src/Form/GridField/RichFilterHeader.php index 4251bbb..4805925 100755 --- a/src/Form/GridField/RichFilterHeader.php +++ b/src/Form/GridField/RichFilterHeader.php @@ -2,7 +2,6 @@ namespace Terraformers\RichFilterHeader\Form\GridField; -use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Injector\Injector; @@ -13,14 +12,12 @@ use SilverStripe\Forms\GridField\GridFieldFilterHeader; use SilverStripe\Forms\GridField\GridState_Data; use SilverStripe\Forms\TextField; +use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataObject; -use SilverStripe\ORM\DataObjectSchema; use SilverStripe\ORM\Filterable; -use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\Filters\SearchFilter; use SilverStripe\ORM\SS_List; -use SilverStripe\ORM\ValidationException; use SilverStripe\View\ArrayData; use SilverStripe\View\SSViewer; @@ -201,6 +198,21 @@ class RichFilterHeader extends GridFieldFilterHeader */ protected $filter_methods = []; + /** + * @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 + */ + public function __construct( + $useLegacy = false, + callable $updateSearchContext = null, + callable $updateSearchForm = null + ) { + // legacy option for filter header component + // we need to use this as new react version of this component uses a different way to scaffold search fields + parent::__construct(true, $updateSearchContext, $updateSearchForm); + } + /** * @param string $class */ @@ -322,31 +334,6 @@ protected function createField(GridField $gridField, $name, $value) return $field; } - /** - * @param string $className - * @param string $relationName - * @return string - * @throws ValidationException - */ - protected function findTableNameForRelation($className, $relationName) - { - $classes = ClassInfo::ancestry($className, true); - foreach ($classes as $class) { - $manyMany = Config::inst()->get($class, 'many_many', Config::UNINHERITED); - if (!empty($manyMany) && is_array($manyMany) && array_key_exists($relationName, $manyMany)) { - return DataObject::getSchema()->tableName($class); - } - } - - throw new ValidationException( - sprintf( - 'Specified relation %s not found in class %s or any of its ancestors', - $relationName, - $className - ) - ); - } - /** * Search for items that contain all keywords * @@ -375,18 +362,10 @@ protected function applyAllKeywordsFilter(Filterable $list, $fieldName, $value) */ protected function applyManyManyRelationFilter(DataList $list, $relationName, $value) { - $tableSeparator = DataObjectSchema::config()->uninherited('table_namespace_separator'); - - $className = $list->dataClass(); - $tableName = $this->findTableNameForRelation($className, $relationName); - - $relationTable = $tableName . $tableSeparator . $relationName; - $relationClassName = singleton($className)->getRelationClass($relationName); - $relationTableName = DataObject::getSchema()->tableName($relationClassName); + $columnName = null; + $list = $list->applyRelation($relationName . '.ID', $columnName); - return $list - ->innerJoin($relationTable, $tableName . '.ID=' . $relationTable . '.' . $tableName . 'ID') - ->filter($relationTableName . 'ID', $value); + return $list->where([$columnName => $value]); } /**