You are here

function gnode_entity_operation in Group 8

Same name and namespace in other branches
  1. 2.0.x modules/gnode/gnode.module \gnode_entity_operation()

Implements hook_entity_operation().

File

modules/gnode/gnode.module, line 25
Enables Group functionality for the Node module.

Code

function gnode_entity_operation(EntityInterface $entity) {
  $operations = [];
  if ($entity
    ->getEntityTypeId() == 'group' && \Drupal::moduleHandler()
    ->moduleExists('views')) {

    /** @var \Drupal\group\Entity\GroupInterface $entity */
    if ($entity
      ->hasPermission('access group_node overview', \Drupal::currentUser())) {

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