You are here

class SocialEventManagersAccessHelper in Open Social 10.3.x

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 modules/social_features/social_event/modules/social_event_managers/src/SocialEventManagersAccessHelper.php \Drupal\social_event_managers\SocialEventManagersAccessHelper
  3. 8.2 modules/social_features/social_event/modules/social_event_managers/src/SocialEventManagersAccessHelper.php \Drupal\social_event_managers\SocialEventManagersAccessHelper
  4. 8.3 modules/social_features/social_event/modules/social_event_managers/src/SocialEventManagersAccessHelper.php \Drupal\social_event_managers\SocialEventManagersAccessHelper
  5. 8.4 modules/social_features/social_event/modules/social_event_managers/src/SocialEventManagersAccessHelper.php \Drupal\social_event_managers\SocialEventManagersAccessHelper
  6. 8.5 modules/social_features/social_event/modules/social_event_managers/src/SocialEventManagersAccessHelper.php \Drupal\social_event_managers\SocialEventManagersAccessHelper
  7. 8.6 modules/social_features/social_event/modules/social_event_managers/src/SocialEventManagersAccessHelper.php \Drupal\social_event_managers\SocialEventManagersAccessHelper
  8. 8.7 modules/social_features/social_event/modules/social_event_managers/src/SocialEventManagersAccessHelper.php \Drupal\social_event_managers\SocialEventManagersAccessHelper
  9. 8.8 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

3 files declare their use of SocialEventManagersAccessHelper
AddEnrolleeAccessCheck.php in modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php
EventAnEnrollController.php in modules/social_features/social_event/modules/social_event_an_enroll/src/Controller/EventAnEnrollController.php
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)) {

          // The owner has access.
          if ($account
            ->id() === $node
            ->getOwnerId()) {
            return 2;
          }
          $event_managers = $node
            ->get('field_event_managers')
            ->getValue();
          foreach ($event_managers as $event_manager) {
            if (isset($event_manager['target_id']) && $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 = self::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.