function workbench_moderation_node_access in Workbench Moderation 8
Same name and namespace in other branches
- 8.2 workbench_moderation.module \workbench_moderation_node_access()
- 7.3 workbench_moderation.module \workbench_moderation_node_access()
- 7 workbench_moderation.module \workbench_moderation_node_access()
- 7.2 workbench_moderation.module \workbench_moderation_node_access()
Implements hook_entity_access().
Nodes in particular should be viewable if unpublished and the user has the appropriate permission. This permission is therefore effectively mandatory for any user that wants to moderate things.
File
- ./
workbench_moderation.module, line 170 - Contains workbench_moderation.module.
Code
function workbench_moderation_node_access(NodeInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\workbench_moderation\ModerationInformationInterface $modinfo */
$moderation_info = Drupal::service('workbench_moderation.moderation_information');
if ($operation == 'view') {
return !$entity
->isPublished() ? AccessResult::allowedIfHasPermission($account, 'view any unpublished content') : AccessResult::neutral();
}
elseif ($operation == 'update' && $moderation_info
->isModeratableEntity($entity) && $entity->moderation_information && $entity->moderation_information->target_id) {
/** @var \Drupal\workbench_moderation\StateTransitionValidation $transition_validation */
$transition_validation = \Drupal::service('workbench_moderation.state_transition_validation');
return $transition_validation
->getValidTransitionTargets($entity, $account) ? AccessResult::neutral() : AccessResult::forbidden();
}
}