You are here

public function WorkflowConfigTransition::isAllowed in Workflow 8

Determines if the current transition between 2 states is allowed.

This is checked in the following locations:

  • in settings;
  • in permissions;
  • by permission hooks, implemented by other modules.

Parameters

\Drupal\user\UserInterface $user: The user to act upon. May have the custom WORKFLOW_ROLE_AUTHOR_RID role.

bool $force: Indicates if the transition must be forced(E.g., by cron, rules).

Return value

bool TRUE if OK, else FALSE.

Overrides WorkflowConfigTransitionInterface::isAllowed

File

src/Entity/WorkflowConfigTransition.php, line 223

Class

WorkflowConfigTransition
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function isAllowed(UserInterface $user, $force = FALSE) {
  $type_id = $this
    ->getWorkflowId();
  if ($user
    ->hasPermission("bypass {$type_id} workflow_transition access")) {

    // Superuser is special. And $force allows Rules to cause transition.
    return TRUE;
  }
  if ($force) {
    return TRUE;
  }
  if ($this
    ->getFromSid() == $this
    ->getToSid()) {

    // Anyone may save an entity without changing state.
    return TRUE;
  }
  return TRUE == array_intersect($user
    ->getRoles(), $this->roles);
}