diff --git a/src/Admin/AdvancedWorkflowAdmin.php b/src/Admin/AdvancedWorkflowAdmin.php
index e77c550a..72412820 100644
--- a/src/Admin/AdvancedWorkflowAdmin.php
+++ b/src/Admin/AdvancedWorkflowAdmin.php
@@ -4,7 +4,6 @@
use InvalidArgumentException;
use SilverStripe\Admin\ModelAdmin;
-use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\FieldList;
@@ -111,8 +110,13 @@ public function getEditForm($id = null, $fields = null)
$config->addComponent(GridFieldEditButton::create());
$config->addComponent(GridFieldDetailForm::create());
$config->getComponentByType(GridFieldPaginator::class)->setItemsPerPage(5);
+
$columns = $config->getComponentByType(GridFieldDataColumns::class);
- $columns->setFieldFormatting($this->setFieldFormatting($config));
+
+ if ($columns instanceof GridFieldDataColumns) {
+ $columns->setDisplayFields($this->getItemDisplayFields())
+ ->setFieldFormatting($this->getItemFieldFormatting());
+ }
// Show items submitted into a workflow for current user to action
$pending = $this->getPendingItems($config);
@@ -165,50 +169,6 @@ public function isAdminUser(Member $user)
return false;
}
- /*
- * By default, we implement GridField_ColumnProvider to allow users to click through to the PagesAdmin.
- * We would also like a "Quick View", that allows users to quickly make a decision on a given workflow-bound
- * content-object
- */
- public function columns()
- {
- $fields = array(
- 'Title' => array(
- 'link' => function ($value, $item) {
- $pageAdminLink = singleton(CMSPageEditController::class)->Link('show');
- return sprintf('%s', $pageAdminLink, $item->Link, $value);
- }
- ),
- 'WorkflowStatus' => array(
- 'text' => function ($value, $item) {
- return $item->WorkflowCurrentAction;
- }
- )
- );
- return $fields;
- }
-
- /*
- * Discreet method used by both intro gridfields to format the target object's links and clickable text
- *
- * @param GridFieldConfig $config
- * @return array $fieldFormatting
- */
- public function setFieldFormatting(&$config)
- {
- $fieldFormatting = array();
- // Parse the column information
- foreach ($this->columns() as $source => $info) {
- if (isset($info['link']) && $info['link']) {
- $fieldFormatting[$source] = '$value';
- }
- if (isset($info['text']) && $info['text']) {
- $fieldFormatting[$source] = $info['text'];
- }
- }
- return $fieldFormatting;
- }
-
/**
* Return content-object data depending on which gridfeld is calling for it
*
@@ -330,7 +290,7 @@ public function getWorkflowService()
*/
private function getItemDisplayFields(): array
{
- if ($this->config()->get('fieldOverrides')) {
+ if ($this->config()->get('fieldOverrides') !== []) {
return $this->config()->get('fieldOverrides');
}
@@ -343,6 +303,10 @@ private function getItemDisplayFields(): array
}
/**
+ * By default, we implement GridField_ColumnProvider to allow users to click through to the PagesAdmin.
+ * We would also like a "Quick View", that allows users to quickly make a decision on a given workflow-bound
+ * content-object
+ *
* @return string[]
*/
private function getItemFieldFormatting(): array
@@ -355,7 +319,11 @@ private function getItemFieldFormatting(): array
return $value;
}
- return $target->Title;
+ if (!$target->hasMethod('CMSEditLink')) {
+ return $value;
+ }
+
+ return sprintf('%s', $target->CMSEditLink(), $target->Title);
},
'LastEdited' => static function (string $value, WorkflowInstance $instance): string {
$target = $instance->getTarget();
@@ -412,15 +380,6 @@ private function getPendingItems(GridFieldConfig $config): ?GridField
$config
);
- $dataColumns = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class);
-
- if (!$dataColumns instanceof GridFieldDataColumns) {
- return $gridField;
- }
-
- $dataColumns->setDisplayFields($this->getItemDisplayFields())
- ->setFieldFormatting($this->getItemFieldFormatting());
-
return $gridField;
}
@@ -454,15 +413,6 @@ private function getSubmittedItems(GridFieldConfig $config): ?GridField
$gridField->getConfig()->removeComponentsByType(GridFieldEditButton::class)
->addComponent(GridFieldWorkflowRestrictedEditButton::create());
- $dataColumns = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class);
-
- if (!$dataColumns instanceof GridFieldDataColumns) {
- return $gridField;
- }
-
- $dataColumns->setDisplayFields($this->getItemDisplayFields())
- ->setFieldFormatting($this->getItemFieldFormatting());
-
return $gridField;
}
}