mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Make GridFieldConfig less susceptible to error when versioned isn't installed
This commit is contained in:
parent
24e6794352
commit
16ad7e8fea
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
* Allows editing of records contained within the GridField, instead of only allowing the ability to view records in
|
||||
* the GridField.
|
||||
@ -21,7 +23,10 @@ class GridFieldConfig_RecordEditor extends GridFieldConfig
|
||||
$this->addComponent($sort = new GridFieldSortableHeader());
|
||||
$this->addComponent($filter = new GridFieldFilterHeader());
|
||||
$this->addComponent(new GridFieldDataColumns());
|
||||
$this->addComponent(new GridFieldVersionedState([ 'Name', 'Title' ]));
|
||||
// @todo Move to versioned module, add via extension instead
|
||||
if (class_exists(Versioned::class)) {
|
||||
$this->addComponent(new GridFieldVersionedState(['Name', 'Title']));
|
||||
}
|
||||
$this->addComponent(new GridFieldEditButton());
|
||||
$this->addComponent(new GridFieldDeleteAction());
|
||||
$this->addComponent(new GridFieldPageCount('toolbar-header-right'));
|
||||
|
@ -1,12 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\Core\Convert;
|
||||
|
||||
/**
|
||||
* @todo Move to siverstripe/versioned module
|
||||
*/
|
||||
class GridFieldVersionedState implements GridField_ColumnProvider
|
||||
{
|
||||
/**
|
||||
* Column name for versioned state
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $column = null;
|
||||
|
||||
/**
|
||||
@ -33,9 +42,12 @@ class GridFieldVersionedState implements GridField_ColumnProvider
|
||||
*/
|
||||
public function augmentColumns($gridField, &$columns)
|
||||
{
|
||||
if (!class_exists(Versioned::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$model = $gridField->getModelClass();
|
||||
$isModelVersioned = $model::has_extension(Versioned::class);
|
||||
|
||||
if (!$isModelVersioned) {
|
||||
return;
|
||||
}
|
||||
@ -61,7 +73,7 @@ class GridFieldVersionedState implements GridField_ColumnProvider
|
||||
*/
|
||||
public function getColumnsHandled($gridField)
|
||||
{
|
||||
return [$this->column];
|
||||
return $this->column ? [$this->column] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +86,6 @@ class GridFieldVersionedState implements GridField_ColumnProvider
|
||||
*/
|
||||
public function getColumnContent($gridField, $record, $columnName)
|
||||
{
|
||||
|
||||
$flagContent = '';
|
||||
$flags = $this->getStatusFlags($record);
|
||||
foreach ($flags as $class => $data) {
|
||||
@ -140,13 +151,16 @@ class GridFieldVersionedState implements GridField_ColumnProvider
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @param DataObject $record - the record to check status for
|
||||
* @param Versioned|DataObject $record - the record to check status for
|
||||
* @return array
|
||||
*/
|
||||
protected function getStatusFlags($record)
|
||||
{
|
||||
$flags = array();
|
||||
if (!$record->hasExtension(Versioned::class)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$flags = [];
|
||||
if ($record->isOnLiveOnly()) {
|
||||
$flags['removedfromdraft'] = array(
|
||||
'text' => _t(__CLASS__ . '.ONLIVEONLYSHORT', 'On live only'),
|
||||
|
Loading…
Reference in New Issue
Block a user