protected function WorkflowTransitionBlock::blockAccess in Workflow 8
Indicates whether the block should be shown.
Blocks with specific access checking should override this method rather than access(), in order to avoid repeating the handling of the $return_as_object argument.
Parameters
\Drupal\Core\Session\AccountInterface $account: The user session for which to check access.
Return value
\Drupal\Core\Access\AccessResult The access result.
Overrides BlockPluginTrait::blockAccess
See also
File
- src/
Plugin/ Block/ WorkflowTransitionBlock.php, line 27
Class
- WorkflowTransitionBlock
- Provides a 'Workflow Transition form' block.
Namespace
Drupal\workflow\Plugin\BlockCode
protected function blockAccess(AccountInterface $account) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
if (!($entity = workflow_url_get_entity())) {
return AccessResult::forbidden();
}
// Only show block on entity view page (when default operation = '').
if ($operation = workflow_url_get_operation()) {
return AccessResult::forbidden();
}
// Only show block if entity has workflow, and user has permission.
foreach (_workflow_info_fields($entity) as $definition) {
$type_id = $definition
->getSetting('workflow_type');
if ($account
->hasPermission("access {$type_id} workflow_transition form")) {
return AccessResult::allowed();
}
}
return AccessResult::forbidden();
}