Skip to content

Commit

Permalink
Merge pull request #5 from silverstripe-terraformers/feature/ss-4.3-u…
Browse files Browse the repository at this point in the history
…pgrade

SS 4.3 upgrade.
  • Loading branch information
mfendeksilverstripe authored Apr 25, 2019
2 parents f6ce436 + cc674ce commit ed17dc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
59 changes: 19 additions & 40 deletions src/Form/GridField/RichFilterHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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]);
}

/**
Expand Down

0 comments on commit ed17dc7

Please sign in to comment.