Skip to content

Commit

Permalink
DEP Deprecate configurable silent failures in GridField components
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 12, 2023
1 parent a1eee2a commit 8c63c0c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/Forms/GridField/GridFieldConfig_Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SilverStripe\Forms\GridField;

use SilverStripe\Dev\Deprecation;

/**
* A simple readonly, paginated view of records, with sortable and searchable
* headers.
Expand All @@ -23,9 +25,11 @@ public function __construct($itemsPerPage = null)
$this->addComponent(GridFieldPageCount::create('toolbar-header-right'));
$this->addComponent($pagination = GridFieldPaginator::create($itemsPerPage));

$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
Deprecation::withNoReplacement(function() use ($sort, $filter, $pagination) {
$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
});

$this->extend('updateConfig');
}
Expand Down
10 changes: 7 additions & 3 deletions src/Forms/GridField/GridFieldConfig_RecordEditor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace SilverStripe\Forms\GridField;

use SilverStripe\Dev\Deprecation;

/**
* Allows editing of records contained within the GridField, instead of only allowing the ability to view records in
* the GridField.
Expand Down Expand Up @@ -30,9 +32,11 @@ public function __construct($itemsPerPage = null, $showPagination = null, $showA
$this->addComponent($pagination = GridFieldPaginator::create($itemsPerPage));
$this->addComponent(GridFieldDetailForm::create(null, $showPagination, $showAdd));

$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
Deprecation::withNoReplacement(function() use ($sort, $filter, $pagination) {
$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
});

$this->extend('updateConfig');
}
Expand Down
10 changes: 7 additions & 3 deletions src/Forms/GridField/GridFieldConfig_RelationEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SilverStripe\Forms\GridField;

use SilverStripe\Dev\Deprecation;

/**
* Similar to {@link GridFieldConfig_RecordEditor}, but adds features to work
* on has-many or many-many relationships.
Expand Down Expand Up @@ -43,9 +45,11 @@ public function __construct($itemsPerPage = null)
$this->addComponent($pagination = GridFieldPaginator::create($itemsPerPage));
$this->addComponent(GridFieldDetailForm::create());

$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
Deprecation::withNoReplacement(function() use ($sort, $filter, $pagination) {
$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
});

$this->extend('updateConfig');
}
Expand Down
7 changes: 7 additions & 0 deletions src/Forms/GridField/GridFieldFilterHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\Schema\FormSchema;
Expand All @@ -27,6 +28,7 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi
* See {@link setThrowExceptionOnBadDataType()}
*
* @var bool
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
protected $throwExceptionOnBadDataType = true;

Expand Down Expand Up @@ -66,17 +68,21 @@ public function getURLHandlers($gridField)
* {@link GridFieldConfig} subclasses set this to false for flexibility.
*
* @param bool $throwExceptionOnBadDataType
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
public function setThrowExceptionOnBadDataType($throwExceptionOnBadDataType)
{
Deprecation::notice('5.2.0', 'Will be removed without equivalent functionality');
$this->throwExceptionOnBadDataType = $throwExceptionOnBadDataType;
}

/**
* See {@link setThrowExceptionOnBadDataType()}
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
public function getThrowExceptionOnBadDataType()
{
Deprecation::notice('5.2.0', 'Will be removed without equivalent functionality');
return $this->throwExceptionOnBadDataType;
}

Expand All @@ -103,6 +109,7 @@ protected function checkDataType($dataList)
if ($dataList instanceof Filterable) {
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."
Expand Down
7 changes: 7 additions & 0 deletions src/Forms/GridField/GridFieldPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
use LogicException;
use SilverStripe\Dev\Deprecation;

/**
* GridFieldPaginator paginates the {@link GridField} list and adds controls
Expand All @@ -33,6 +34,7 @@ class GridFieldPaginator extends AbstractGridFieldComponent implements GridField

/**
* See {@link setThrowExceptionOnBadDataType()}
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
protected $throwExceptionOnBadDataType = true;

Expand All @@ -57,9 +59,11 @@ public function __construct($itemsPerPage = null)
*
* @param bool $throwExceptionOnBadDataType
* @return $this
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
public function setThrowExceptionOnBadDataType($throwExceptionOnBadDataType)
{
Deprecation::notice('5.2.0', 'Will be removed without equivalent functionality');
$this->throwExceptionOnBadDataType = $throwExceptionOnBadDataType;
return $this;
}
Expand All @@ -68,9 +72,11 @@ public function setThrowExceptionOnBadDataType($throwExceptionOnBadDataType)
* See {@link setThrowExceptionOnBadDataType()}
*
* @return bool
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
public function getThrowExceptionOnBadDataType()
{
Deprecation::notice('5.2.0', 'Will be removed without equivalent functionality');
return $this->throwExceptionOnBadDataType;
}

Expand All @@ -86,6 +92,7 @@ protected function checkDataType($dataList)
if ($dataList instanceof Limitable) {
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."
Expand Down
7 changes: 7 additions & 0 deletions src/Forms/GridField/GridFieldSortableHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\View\SSViewer;
use LogicException;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;

/**
* GridFieldSortableHeader adds column headers to a {@link GridField} that can
Expand All @@ -26,6 +27,7 @@ class GridFieldSortableHeader extends AbstractGridFieldComponent implements Grid
* See {@link setThrowExceptionOnBadDataType()}
*
* @var bool
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
protected $throwExceptionOnBadDataType = true;

Expand All @@ -45,9 +47,11 @@ class GridFieldSortableHeader extends AbstractGridFieldComponent implements Grid
*
* @param bool $throwExceptionOnBadDataType
* @return $this
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
public function setThrowExceptionOnBadDataType($throwExceptionOnBadDataType)
{
Deprecation::notice('5.2.0', 'Will be removed without equivalent functionality');
$this->throwExceptionOnBadDataType = $throwExceptionOnBadDataType;
return $this;
}
Expand All @@ -56,9 +60,11 @@ public function setThrowExceptionOnBadDataType($throwExceptionOnBadDataType)
* See {@link setThrowExceptionOnBadDataType()}
*
* @return bool
* @deprecated 5.2.0 Will be removed without equivalent functionality
*/
public function getThrowExceptionOnBadDataType()
{
Deprecation::notice('5.2.0', 'Will be removed without equivalent functionality');
return $this->throwExceptionOnBadDataType;
}

Expand All @@ -74,6 +80,7 @@ protected function checkDataType($dataList)
if ($dataList instanceof Sortable) {
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."
Expand Down

0 comments on commit 8c63c0c

Please sign in to comment.