You are here

class SocialEventManagersAccessHelper in Open Social 8

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

Helper class for checking update access on event managers nodes.

Hierarchy

Expanded class hierarchy of SocialEventManagersAccessHelper

1 file declares its use of SocialEventManagersAccessHelper
social_event_managers.module in modules/social_features/social_event/modules/social_event_managers/social_event_managers.module
Contains social_event_managers.module.

File

modules/social_features/social_event/modules/social_event_managers/src/SocialEventManagersAccessHelper.php, line 12

Namespace

Drupal\social_event_managers
View source
class SocialEventManagersAccessHelper {

  /**
   * NodeAccessCheck for given operation, node and user account.
   */
  public static function nodeAccessCheck(NodeInterface $node, $op, AccountInterface $account) {
    if ($op === 'update') {

      // Only for events.
      if ($node
        ->getType() === 'event') {

        // Only continue if the user has access to view the event.
        if ($node
          ->access('view', $account)) {
          $event_managers = $node
            ->get('field_event_managers')
            ->getValue();
          foreach ($event_managers as $event_manager) {
            if ($account
              ->id() == $event_manager['target_id']) {
              return 2;
            }
          }

          // No hits, so we assume the user is not an event manager.
          return 1;
        }
      }
    }
    return 0;
  }

  /**
   * Gets the Entity access for the given node.
   */
  public static function getEntityAccessResult(NodeInterface $node, $op, AccountInterface $account) {
    $access = SocialEventManagersAccessHelper::nodeAccessCheck($node, $op, $account);
    switch ($access) {
      case 2:
        return AccessResult::allowed()
          ->cachePerPermissions()
          ->addCacheableDependency($node);
      case 1:
        return AccessResult::forbidden();
    }
    return AccessResult::neutral();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialEventManagersAccessHelper::getEntityAccessResult public static function Gets the Entity access for the given node.
SocialEventManagersAccessHelper::nodeAccessCheck public static function NodeAccessCheck for given operation, node and user account.