You are here

function social_event_manager_or_organizer in Open Social 8.5

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.6 modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  3. 8.7 modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  4. 8.8 modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  5. 10.3.x modules/social_features/social_event/social_event.module \social_event_manager_or_organizer()
  6. 10.0.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\Entity\Node|null $node: The node the current user could be organizer of.

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

Return value

bool If the user is actually a manager or organizer.

8 calls to social_event_manager_or_organizer()
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
SocialEventManagersAddEnrolleeForm::submitForm in modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php
Form submission handler.
SocialEventManagersSendEmail::access in modules/social_features/social_event/modules/social_event_managers/src/Plugin/Action/SocialEventManagersSendEmail.php
social_event_managers_entity_access in modules/social_features/social_event/modules/social_event_managers/social_event_managers.module
Implements hook_entity_access().

... See full list

File

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

Code

function social_event_manager_or_organizer(Node $node = NULL, $skipTrustedRoles = FALSE) {
  $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 ($skipTrustedRoles === FALSE && $account
    ->hasPermission('manage everything enrollments')) {
    return TRUE;
  }
  if ($node === NULL) {

    /** @var \Drupal\node\NodeInterface $node */
    $node = \Drupal::routeMatch()
      ->getParameter('node');

    // Or if it's an organizer for the node.
    if (!$node instanceof NodeInterface && !$node instanceof Node) {
      $node = \Drupal::entityTypeManager()
        ->getStorage('node')
        ->load($node);
    }

    // If we are altering / deleting an Event Enrollment check if user
    // is manager or organizer from the referenced node.
    if (!empty(\Drupal::routeMatch()
      ->getParameter('event_enrollment'))) {

      /** @var \Drupal\social_event\Entity\EventEnrollment $event_enrollment */
      $event_enrollment = \Drupal::routeMatch()
        ->getParameter('event_enrollment');
      $event_id = $event_enrollment
        ->getFieldValue('field_event', 'target_id');
      $node = \Drupal::entityTypeManager()
        ->getStorage('node')
        ->load($event_id);
    }
  }
  if ($node !== NULL && $node
    ->bundle() === 'event' && !$node->field_event_managers
    ->isEmpty()) {
    foreach ($node->field_event_managers
      ->getValue() as $value) {
      if ($value && $value['target_id'] === $account
        ->id()) {
        return TRUE;
      }
    }
  }
  return FALSE;
}