Skip to content

Commit

Permalink
NEW Extend new AbstractGridFieldComponent class
Browse files Browse the repository at this point in the history
This makes the `GridFieldSortableRows` component `Injectable`, and allows any future enhancements in the new abstract class to automatically apply without requiring additional changes in this module.

The class is introduced in silverstripe/framework 4.11.0 so the dependency constraint needs to be updated.

Also take use dependency injection instead of the `new` keyword when instantiating GridFields, their components, and configs.
  • Loading branch information
GuySartorelli committed Feb 12, 2022
1 parent 810716e commit f9b55bc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require": {
"php": "^7.4 || ^8.0",
"silverstripe/cms": "^4",
"silverstripe/framework": "^4.10",
"silverstripe/framework": "^4.11",
"silverstripe/admin": "^1",
"silverstripe/versioned": "^1",
"symfony/yaml": "^3 || ^4"
Expand Down
10 changes: 5 additions & 5 deletions src/Admin/AdvancedWorkflowAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public function getEditForm($id = null, $fields = null)
}

// Pending/Submitted items GridField Config
$config = new GridFieldConfig_Base();
$config->addComponent(new GridFieldEditButton());
$config->addComponent(new GridFieldDetailForm());
$config = GridFieldConfig_Base::create();
$config->addComponent(GridFieldEditButton::create());
$config->addComponent(GridFieldDetailForm::create());
$config->getComponentByType(GridFieldPaginator::class)->setItemsPerPage(5);
$columns = $config->getComponentByType(GridFieldDataColumns::class);
$columns->setFieldFormatting($this->setFieldFormatting($config));
Expand Down Expand Up @@ -173,7 +173,7 @@ public function getEditForm($id = null, $fields = null)

$formFieldBottom->setForm($form);
$formFieldBottom->getConfig()->removeComponentsByType(GridFieldEditButton::class);
$formFieldBottom->getConfig()->addComponent(new GridFieldWorkflowRestrictedEditButton());
$formFieldBottom->getConfig()->addComponent(GridFieldWorkflowRestrictedEditButton::create());
$form->Fields()->insertBefore($definitionGridFieldName, $formFieldBottom);
}

Expand All @@ -189,7 +189,7 @@ public function getEditForm($id = null, $fields = null)

$grid->getConfig()->getComponentByType(GridFieldDetailForm::class)
->setItemRequestClass(WorkflowDefinitionItemRequestClass::class);
$grid->getConfig()->addComponent(new GridFieldExportAction());
$grid->getConfig()->addComponent(GridFieldExportAction::create());
$grid->getConfig()->removeComponentsByType(GridFieldExportButton::class);
$grid->getConfig()->removeComponentsByType(GridFieldImportButton::class);
}
Expand Down
16 changes: 8 additions & 8 deletions src/DataObjects/WorkflowDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,31 +342,31 @@ public function getCMSFields()
'WorkflowStatus' => ['Active', 'Paused']
]);

$active = new GridField(
$active = GridField::create(
'Active',
_t('WorkflowDefinition.WORKFLOWACTIVEIINSTANCES', 'Active Workflow Instances'),
$active,
new GridFieldConfig_RecordEditor()
GridFieldConfig_RecordEditor::create()
);

$active->getConfig()->removeComponentsByType(GridFieldAddNewButton::class);
$active->getConfig()->removeComponentsByType(GridFieldDeleteAction::class);

if (!Permission::check('REASSIGN_ACTIVE_WORKFLOWS')) {
$active->getConfig()->removeComponentsByType(GridFieldEditButton::class);
$active->getConfig()->addComponent(new GridFieldViewButton());
$active->getConfig()->addComponent(new GridFieldDetailForm());
$active->getConfig()->addComponent(GridFieldViewButton::create());
$active->getConfig()->addComponent(GridFieldDetailForm::create());
}

$completed = $this->Instances()->filter([
'WorkflowStatus' => ['Complete', 'Cancelled']
]);

$config = new GridFieldConfig_Base();
$config->addComponent(new GridFieldEditButton());
$config->addComponent(new GridFieldDetailForm());
$config = GridFieldConfig_Base::create();
$config->addComponent(GridFieldEditButton::create());
$config->addComponent(GridFieldDetailForm::create());

$completed = new GridField(
$completed = GridField::create(
'Completed',
_t('WorkflowDefinition.WORKFLOWCOMPLETEDIINSTANCES', 'Completed Workflow Instances'),
$completed,
Expand Down
2 changes: 1 addition & 1 deletion src/DataObjects/WorkflowInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function getCMSFields()
'WorkflowID' => $this->ID
));

$grid = new GridField(
$grid = GridField::create(
'Actions',
_t('WorkflowInstance.ActionLogTitle', 'Log'),
$items
Expand Down
8 changes: 4 additions & 4 deletions src/Extensions/WorkflowApplicable.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ public function updateFields(FieldList $fields)
}

if ($this->owner->ID) {
$config = new GridFieldConfig_Base();
$config->addComponent(new GridFieldEditButton());
$config->addComponent(new GridFieldDetailForm());
$config = GridFieldConfig_Base::create();
$config->addComponent(GridFieldEditButton::create());
$config->addComponent(GridFieldDetailForm::create());

$insts = $this->owner->WorkflowInstances();
$log = new GridField(
$log = GridField::create(
'WorkflowLog',
_t('WorkflowApplicable.WORKFLOWLOG', 'Workflow Log'),
$insts,
Expand Down
3 changes: 2 additions & 1 deletion src/Forms/gridfield/GridFieldExportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\GridField\AbstractGridFieldComponent;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridField_ActionProvider;
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
Expand All @@ -22,7 +23,7 @@
* @license BSD License (http://silverstripe.org/bsd-license/)
* @package advancedworkflow
*/
class GridFieldExportAction implements GridField_ColumnProvider, GridField_ActionProvider
class GridFieldExportAction extends AbstractGridFieldComponent implements GridField_ColumnProvider, GridField_ActionProvider
{
/**
* Add a column 'Delete'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Symbiote\AdvancedWorkflow\Forms\GridField;

use SilverStripe\Control\Controller;
use SilverStripe\Forms\GridField\AbstractGridFieldComponent;
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Security\Permission;
Expand All @@ -14,7 +15,7 @@
*
* @package advancedworkflow
*/
class GridFieldWorkflowRestrictedEditButton implements GridField_ColumnProvider
class GridFieldWorkflowRestrictedEditButton extends AbstractGridFieldComponent implements GridField_ColumnProvider
{
/**
* Add a column
Expand Down

0 comments on commit f9b55bc

Please sign in to comment.