Commit 0aa28234 authored by Nikolay Lobachev's avatar Nikolay Lobachev
Browse files

Issue #3293317 by LOBsTerr: Users cannot see the name of the Group that they were invited

parent 7388281e
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -6,9 +6,12 @@
 */

use Drupal\Component\Utility\Html;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\ginvite\Event\UserLoginWithInvitationEvent;
use Drupal\ginvite\Event\UserRegisteredFromInvitationEvent;
@@ -466,3 +469,23 @@ function ginvite_user_login(UserInterface $user) {
    $event_dispatcher->dispatch($event, UserLoginWithInvitationEvent::EVENT_NAME);
  }
}

/**
 * Implements hook_ENTITY_TYPE_access().
 */
function ginvite_group_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation == 'view' || $operation == 'view label') {
    $properties = [
      'entity_id' => $account->id(),
      'gid' => $entity->id(),
      'invitation_status' => GroupInvitation::INVITATION_PENDING,
    ];

    $invitations = \Drupal::service('ginvite.invitation_loader')->loadByProperties($properties);
    if (!empty($invitations)) {
      return AccessResult::allowed();
    }
  }

  return AccessResult::neutral();
}