You are here

function gevent_entity_operation in Event 8

Implements hook_entity_operation().

File

modules/gevent/gevent.module, line 21
Enables Group functionality for the Event module.

Code

function gevent_entity_operation($entity) {
  $operations = [];
  if ($entity
    ->getEntityTypeId() == 'group' && \Drupal::moduleHandler()
    ->moduleExists('views')) {
    if ($entity
      ->hasPermission('access group_event overview', \Drupal::currentUser())) {

      /** @var \Symfony\Component\Routing\RouterInterface $router */
      $router = \Drupal::service('router.no_access_checks');
      if ($router
        ->getRouteCollection()
        ->get('view.group_events.page_1') !== NULL) {
        $operations['events'] = [
          'title' => t('Events'),
          'weight' => 20,
          'url' => Url::fromRoute('view.group_events.page_1', [
            'group' => $entity
              ->id(),
          ]),
        ];
      }
    }
  }
  return $operations;
}