Skip to content

Commit

Permalink
Merge pull request #243 from SilbinaryWolf/fix-dontaddnotallowedactio…
Browse files Browse the repository at this point in the history
…nsfrontend

fix(WorkflowInstance/FrontendActions): Changed unexecutable actions on the frontend to be hidden so the behaviour is more consistent with the backend.
  • Loading branch information
nyeholt committed Apr 27, 2016
2 parents 6d198eb + fedf56e commit 8faccf0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion code/dataobjects/WorkflowInstance.php
Expand Up @@ -49,6 +49,14 @@ class WorkflowInstance extends DataObject {
'Created'
);

/**
* If set to true, actions that cannot be executed by the user will not show
* on the frontend (just like the backend).
*
* @var boolean
*/
private static $hide_disabled_actions_on_frontend = false;

/**
* Get the CMS view of the instance. This is used to display the log of
* this workflow, and options to reassign if the workflow hasn't been
Expand Down Expand Up @@ -551,6 +559,8 @@ public function getFrontEndWorkflowActions() {
$options = $action->getValidTransitions();
$actions = new FieldList();

$hide_disabled_actions_on_frontend = $this->config()->hide_disabled_actions_on_frontend;

foreach ($options as $option) {
$btn = new FormAction("transition_{$option->ID}", $option->Title);

Expand All @@ -560,7 +570,13 @@ public function getFrontEndWorkflowActions() {
}

// disable the button if canExecute() returns false
if(!$option->canExecute($this)){
if(!$option->canExecute($this))
{
if ($hide_disabled_actions_on_frontend)
{
continue;
}

$btn = $btn->performReadonlyTransformation();
$btn->addExtraClass('hide');
}
Expand Down

0 comments on commit 8faccf0

Please sign in to comment.