You are here

function social_event_invite_entity_operation_alter in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_event/modules/social_event_invite/social_event_invite.module \social_event_invite_entity_operation_alter()
  2. 10.0.x modules/social_features/social_event/modules/social_event_invite/social_event_invite.module \social_event_invite_entity_operation_alter()
  3. 10.1.x modules/social_features/social_event/modules/social_event_invite/social_event_invite.module \social_event_invite_entity_operation_alter()
  4. 10.2.x modules/social_features/social_event/modules/social_event_invite/social_event_invite.module \social_event_invite_entity_operation_alter()

Implements hook_entity_operation_alter().

File

modules/social_features/social_event/modules/social_event_invite/social_event_invite.module, line 254
The Social event invite enroll module.

Code

function social_event_invite_entity_operation_alter(array &$operations, EntityInterface $entity) {

  // Get the node, so we can pass it as a parameter.
  $node = \Drupal::routeMatch()
    ->getParameter('node');

  // Get the route name.
  $route_name = \Drupal::routeMatch()
    ->getRouteName();

  // Get the current user.
  $user_account = \Drupal::currentUser()
    ->getAccount();

  // Check if the entity type is one of event_enrollment and that we're on the
  // correct view. Otherwise it would update all actions across the platform.
  if ($entity
    ->getEntityTypeId() === 'event_enrollment') {

    // Build operations for the event invites overview for the owner/manager.
    if (social_event_manager_or_organizer() && $route_name === 'view.event_manage_enrollment_invites.page_manage_enrollment_invites') {

      // Empty the current operations.
      $operations = [];

      // Add the "Cancel invite" option.
      $operations['cancel']['title'] = t('Cancel invite');
      $operations['cancel']['url'] = Url::fromRoute('social_event_invite.cancel_enrollment_invite', [
        'node' => $node,
        'event_enrollment' => $entity
          ->id(),
      ]);

      // If the user has declined or if the invite is invalid or expired,
      // provide a delete button so that the event_enrollment can be
      // deleted from this event.
      $delete_statusses = [
        EventEnrollmentInterface::REQUEST_OR_INVITE_DECLINED,
        EventEnrollmentInterface::INVITE_INVALID_OR_EXPIRED,
      ];
      if (in_array((int) $entity->field_request_or_invite_status->value, $delete_statusses)) {
        $operations = [];

        // Add the "Delete invite" option.
        $operations['delete']['title'] = t('Remove');
        $operations['delete']['url'] = Url::fromRoute('social_event_invite.cancel_enrollment_invite', [
          'node' => $node,
          'event_enrollment' => $entity
            ->id(),
        ]);
      }
      if ((int) $entity->field_request_or_invite_status->value === EventEnrollmentInterface::INVITE_ACCEPTED_AND_JOINED) {
        $operations = [];
      }
    }

    // Build operations for the users overview for event invites.
    if ($route_name === 'view.user_event_invites.page_user_event_invites') {

      // Empty the current operations.
      $operations = [];

      // Add the "Accept invite" option.
      $operations['accept']['title'] = t('Accept invite');
      $operations['accept']['url'] = Url::fromRoute('social_event_invite.update_enrollment_invite', [
        'user' => $user_account
          ->id(),
        'event_enrollment' => $entity
          ->id(),
        'accept_decline' => '1',
      ]);

      // Add the "Decline invite" option.
      $operations['decline']['title'] = t('Decline invite');
      $operations['decline']['url'] = Url::fromRoute('social_event_invite.update_enrollment_invite', [
        'user' => $user_account
          ->id(),
        'event_enrollment' => $entity
          ->id(),
        'accept_decline' => '0',
      ]);
    }
  }
}