content_moderation_node_access(NodeInterface $node, $operation, AccountInterface $account)
Implements hook_node_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
- core/modules/content_moderation/content_moderation.module, line 173
- Contains content_moderation.module.
Code
function content_moderation_node_access(NodeInterface $node, $operation, AccountInterface $account) { /** @var \Drupal\content_moderation\ModerationInformationInterface $moderation_info */ $moderation_info = Drupal::service('content_moderation.moderation_information'); $access_result = NULL; if ($operation === 'view') { $access_result = (!$node->isPublished()) ? AccessResult::allowedIfHasPermission($account, 'view any unpublished content') : AccessResult::neutral(); $access_result->addCacheableDependency($node); } elseif ($operation === 'update' && $moderation_info->isModeratedEntity($node) && $node->moderation_state && $node->moderation_state->target_id) { /** @var \Drupal\content_moderation\StateTransitionValidation $transition_validation */ $transition_validation = \Drupal::service('content_moderation.state_transition_validation'); $valid_transition_targets = $transition_validation->getValidTransitionTargets($node, $account); $access_result = $valid_transition_targets ? AccessResult::neutral() : AccessResult::forbidden(); $access_result->addCacheableDependency($node); $access_result->addCacheableDependency($account); foreach ($valid_transition_targets as $valid_transition_target) { $access_result->addCacheableDependency($valid_transition_target); } } return $access_result; }
Please login to continue.