You are here

function social_event_manager_or_organizer in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  2. 8.5 modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  3. 8.6 modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  4. 8.7 modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  5. 8.8 modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  6. 10.3.x modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  7. 10.1.x modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  8. 10.2.x modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()

Check if the user is allowed to manage Enrollments.

Parameters

\Drupal\node\NodeInterface|null $node: The node the current user could be organizer of.

bool $skip_trusted_roles: Should we skip CM/SM with the manage everything enrollments.

Return value

bool If the user is actually a manager or organizer.

18 calls to social_event_manager_or_organizer()
CancelEnrollInviteController::access in modules/social_features/social_event/modules/social_event_invite/src/Controller/CancelEnrollInviteController.php
Checks access for a specific request.
EnrollActionForm::buildForm in modules/social_features/social_event/src/Form/EnrollActionForm.php
Form constructor.
EnrollRequestsOverviewSubscriber::checkAccessToEnrollRequestsOverview in modules/social_features/social_event/src/Routing/EnrollRequestsOverviewSubscriber.php
Check if the user is allowed to view this overview.
EventAnEnrollManager::getGuestName in modules/social_features/social_event/modules/social_event_an_enroll/src/EventAnEnrollManager.php
Returns guest name.
EventEnrollmentEntityDeleteAction::access in modules/social_features/social_event/modules/social_event_managers/src/Plugin/Action/EventEnrollmentEntityDeleteAction.php
Checks object access.

... See full list

File

modules/social_features/social_event/social_event.module, line 126
The Social event module.

Code

function social_event_manager_or_organizer(NodeInterface $node = NULL, $skip_trusted_roles = FALSE) {
  $social_event_manager_or_organizer =& drupal_static(__FUNCTION__);
  if (!isset($social_event_manager_or_organizer)) {
    $account = \Drupal::currentUser();

    // Allow if user has the manage everything permission.
    // We can skip this to make sure we truly only check organizer & managers
    // used for context in notifications.
    if ($skip_trusted_roles === FALSE && $account
      ->hasPermission('manage everything enrollments')) {
      $result = TRUE;
    }
    if (!$node && !isset($result)) {

      // Get the current event node.
      $node = social_event_get_current_event();

      // If there's no node, we might be looking at an event enrollment.
      if (!$node) {

        // If we are altering / deleting an Event Enrollment check if user
        // is manager or organizer from the referenced node.
        $event_enrollment = \Drupal::routeMatch()
          ->getParameter('event_enrollment');
        if ($event_enrollment instanceof EventEnrollmentInterface) {
          $node = $event_enrollment->field_event->entity;
        }
      }
    }

    // If we now have a node we can check if there are event managers.
    if ($node instanceof NodeInterface && !isset($result) && $node
      ->bundle() === 'event') {

      // The event owner has access.
      if ($node
        ->getOwnerId() === $account
        ->id()) {
        $result = TRUE;
      }

      // Check if the user is an event manager/organizer.
      if (!isset($result) && $node
        ->hasField('field_event_managers') && !$node->field_event_managers
        ->isEmpty()) {
        foreach ($node->field_event_managers
          ->getValue() as $value) {
          if ($value && $value['target_id'] === $account
            ->id()) {
            $result = TRUE;
            break;
          }
        }
      }
    }

    // No result means the user does not have access.
    if (!isset($result)) {
      $result = FALSE;
    }
    $social_event_manager_or_organizer = $result;
  }
  return $social_event_manager_or_organizer;
}