Skip to content

Commit

Permalink
API Combine Sortable, Filterable and Limitable into SS_List
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 21, 2024
1 parent ba97de9 commit 3ce511c
Show file tree
Hide file tree
Showing 18 changed files with 173 additions and 266 deletions.
11 changes: 4 additions & 7 deletions src/Forms/GridField/GridField.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\Limitable;
use SilverStripe\Model\List\Sortable;
use SilverStripe\Model\List\SS_List;
use SilverStripe\View\HTML;
use SilverStripe\Model\ModelData;
Expand Down Expand Up @@ -86,7 +83,7 @@ class GridField extends FormField
/**
* Data source.
*
* @var SS_List&Filterable&Sortable&Limitable
* @var SS_List
*/
protected $list = null;

Expand Down Expand Up @@ -397,7 +394,7 @@ public function getCastedValue($value, $castingDefinition)
/**
* Set the data source.
*
* @param SS_List&Filterable&Sortable&Limitable $list
* @param SS_List $list
*
* @return $this
*/
Expand All @@ -411,7 +408,7 @@ public function setList(SS_List $list)
/**
* Get the data source.
*
* @return SS_List&Filterable&Sortable&Limitable
* @return SS_List
*/
public function getList()
{
Expand All @@ -421,7 +418,7 @@ public function getList()
/**
* Get the data source after applying every {@link GridField_DataManipulator} to it.
*
* @return SS_List&Filterable&Sortable&Limitable
* @return SS_List
*/
public function getManipulatedList()
{
Expand Down
7 changes: 3 additions & 4 deletions src/Forms/GridField/GridFieldFilterHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\Schema\FormSchema;
use SilverStripe\Model\List\Filterable;
use SilverStripe\ORM\Search\SearchContext;
use SilverStripe\Model\List\SS_List;
use SilverStripe\Model\ArrayData;
Expand Down Expand Up @@ -109,13 +108,13 @@ public function setSearchField(string $field): GridFieldFilterHeader
*/
protected function checkDataType($dataList)
{
if ($dataList instanceof Filterable) {
if ($dataList instanceof SS_List) {
return true;
} else {
// This will be changed to always throw an exception in a future major release.
if ($this->throwExceptionOnBadDataType) {
throw new LogicException(
static::class . " expects an SS_Filterable list to be passed to the GridField."
static::class . " expects an SS_List list to be passed to the GridField."
);
}
return false;
Expand Down Expand Up @@ -209,7 +208,7 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList)
public function canFilterAnyColumns($gridField)
{
$list = $gridField->getList();
if (!($list instanceof Filterable) || !$this->checkDataType($list)) {
if (!($list instanceof SS_List) || !$this->checkDataType($list)) {
return false;
}
$modelClass = $gridField->getModelClass();
Expand Down
3 changes: 1 addition & 2 deletions src/Forms/GridField/GridFieldLazyLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\TabSet;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
Expand All @@ -28,7 +27,7 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList)
{
// If we are lazy loading an empty the list
if ($this->isLazy($gridField)) {
if ($dataList instanceof Filterable) {
if ($dataList instanceof SS_List) {
// If our original list can be filtered, filter out all results.
$dataList = $dataList->byIDs([-1]);
} else {
Expand Down
7 changes: 3 additions & 4 deletions src/Forms/GridField/GridFieldPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\Forms\GridField;

use SilverStripe\Core\Config\Configurable;
use SilverStripe\Model\List\Limitable;
use SilverStripe\Model\List\SS_List;
use SilverStripe\ORM\UnsavedRelationList;
use SilverStripe\Model\ArrayData;
Expand Down Expand Up @@ -89,13 +88,13 @@ public function getThrowExceptionOnBadDataType()
*/
protected function checkDataType($dataList)
{
if ($dataList instanceof Limitable) {
if ($dataList instanceof SS_List) {
return true;
} else {
// This will be changed to always throw an exception in a future major release.
if ($this->throwExceptionOnBadDataType) {
throw new LogicException(
static::class . " expects an SS_Limitable list to be passed to the GridField."
static::class . " expects an SS_List list to be passed to the GridField."
);
}
return false;
Expand Down Expand Up @@ -183,7 +182,7 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList)
$startRow = 0;
}

if (!($dataList instanceof Limitable) || ($dataList instanceof UnsavedRelationList)) {
if (!($dataList instanceof SS_List) || ($dataList instanceof UnsavedRelationList)) {
return $dataList;
}

Expand Down
7 changes: 3 additions & 4 deletions src/Forms/GridField/GridFieldSortableHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\DataObjectSchema;
use SilverStripe\Model\List\Sortable;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\Model\List\SS_List;
use SilverStripe\ORM\DataObject;
Expand Down Expand Up @@ -78,13 +77,13 @@ public function getThrowExceptionOnBadDataType()
*/
protected function checkDataType($dataList)
{
if ($dataList instanceof Sortable) {
if ($dataList instanceof SS_List) {
return true;
} else {
// This will be changed to always throw an exception in a future major release.
if ($this->throwExceptionOnBadDataType) {
throw new LogicException(
static::class . " expects an SS_Sortable list to be passed to the GridField."
static::class . " expects an SS_List list to be passed to the GridField."
);
}
return false;
Expand Down Expand Up @@ -246,7 +245,7 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat
* {@link DataQuery} first.
*
* @param GridField $gridField
* @param SS_List&Sortable $dataList
* @param SS_List $dataList
* @return SS_List
*/
public function getManipulatedData(GridField $gridField, SS_List $dataList)
Expand Down
11 changes: 4 additions & 7 deletions src/Model/List/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
/**
* A list object that wraps around an array of objects or arrays.
*
* Note that (like DataLists), the implementations of the methods from SS_Filterable, SS_Sortable and
* SS_Limitable return a new instance of ArrayList, rather than modifying the existing instance.
* Note that (like DataLists), the implementations of the methods from SS_List return a new instance of ArrayList,
* rather than modifying the existing instance.
*
* For easy reference, methods that operate in this way are:
*
Expand All @@ -28,11 +28,8 @@
*
* @template T
* @implements SS_List<T>
* @implements Filterable<T>
* @implements Sortable<T>
* @implements Limitable<T>
*/
class ArrayList extends ModelData implements SS_List, Filterable, Sortable, Limitable
class ArrayList extends ModelData implements SS_List
{
use SearchFilterable;

Expand Down Expand Up @@ -597,7 +594,7 @@ public function find($key, $value)
/**
* Filter the list to include items with these characteristics
*
* @see Filterable::filter()
* @see SS_List::filter()
* @example $list->filter('Name', 'bob'); // only bob in the list
* @example $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
* @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the Age 21 in list
Expand Down
107 changes: 0 additions & 107 deletions src/Model/List/Filterable.php

This file was deleted.

32 changes: 0 additions & 32 deletions src/Model/List/Limitable.php

This file was deleted.

17 changes: 7 additions & 10 deletions src/Model/List/ListDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
* functionality. It passes through list methods to the underlying list
* implementation.
*
* @template TList of SS_List&Sortable&Filterable&Limitable
* @template TList of SS_List
* @template T
* @implements SS_List<T>
* @implements Sortable<T>
* @implements Filterable<T>
* @implements Limitable<T>
*/
abstract class ListDecorator extends ModelData implements SS_List, Sortable, Filterable, Limitable
abstract class ListDecorator extends ModelData implements SS_List
{
/**
* @var TList<T>
Expand All @@ -28,7 +25,7 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
/**
* @param TList<T> $list
*/
public function __construct(SS_List&Sortable&Filterable&Limitable $list)
public function __construct(SS_List $list)
{
$this->setList($list);
parent::__construct();
Expand All @@ -37,7 +34,7 @@ public function __construct(SS_List&Sortable&Filterable&Limitable $list)
/**
* @return TList<T>
*/
public function getList(): SS_List&Sortable&Filterable&Limitable
public function getList(): SS_List
{
return $this->list;
}
Expand All @@ -53,7 +50,7 @@ public function getList(): SS_List&Sortable&Filterable&Limitable
* @param TListA<TA> $list
* @return static<TListA, TA>
*/
public function setList(SS_List&Sortable&Filterable&Limitable $list): ListDecorator
public function setList(SS_List $list): ListDecorator
{
$this->list = $list;
$this->failover = $this->list;
Expand Down Expand Up @@ -249,7 +246,7 @@ public function filterAny()
/**
* Note that, in the current implementation, the filtered list will be an ArrayList, but this may change in a
* future implementation.
* @see Filterable::filterByCallback()
* @see SS_List::filterByCallback()
*
* @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })
* @param callable $callback
Expand All @@ -275,7 +272,7 @@ public function filterByCallback($callback)
/**
* @return TList<T>
*/
public function limit(?int $length, int $offset = 0): SS_List&Sortable&Filterable&Limitable
public function limit(?int $length, int $offset = 0): SS_List
{
return $this->list->limit($length, $offset);
}
Expand Down
Loading

0 comments on commit 3ce511c

Please sign in to comment.