You are here

function social_event_managers_node_access in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  2. 8 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  3. 8.2 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  4. 8.3 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  5. 8.5 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  6. 8.6 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  7. 8.7 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  8. 8.8 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  9. 10.3.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  10. 10.0.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  11. 10.1.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()
  12. 10.2.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_node_access()

Implements hook_node_access().

Remember: if any module returns forbidden and denies access to certain node and operation it will not allow the user to do the operation on the node.

We need this implementation because we also want to give edit access to event manager regardless these scenarios thought of in gnode_node_access:

  • is a member in the group and:
  • has edit own or edit any permission in the group

The gnode module specifically returns allowed if any of the above scenarios are met, but forbidden in all the other scenarios. Our code ensures that if we are in operation update and if gnode already returns forbidden we are able to return an allowed if user is an event manager.

File

modules/social_features/social_event/modules/social_event_managers/social_event_managers.module, line 159
Contains social_event_managers.module.

Code

function social_event_managers_node_access(NodeInterface $node, $op, AccountInterface $account) {

  // Only continue if the gnode module is enabled.
  if (function_exists('gnode_node_access')) {
    $gnode_access = gnode_node_access($node, $op, $account);
    if ($op === 'update') {
      if ($gnode_access instanceof AccessResultForbidden) {
        $social_event_managers_access = SocialEventManagersAccessHelper::getEntityAccessResult($node, $op, $account);

        // Only return the result of SocialEventManagersAccessHelper
        // if it is allowed.
        if ($social_event_managers_access instanceof AccessResultAllowed) {
          return $social_event_managers_access;
        }
      }
      return $gnode_access;
    }
    return $gnode_access;
  }
  return SocialEventManagersAccessHelper::getEntityAccessResult($node, $op, $account);
}