You are here

public function OgAdminRoutesController::overview in Organic groups 8

Show all the available admin routes.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match service.

Return value

array List of available admin routes for the current group.

File

src/Controller/OgAdminRoutesController.php, line 67

Class

OgAdminRoutesController
The OG admin routes controller.

Namespace

Drupal\og\Controller

Code

public function overview(RouteMatchInterface $route_match) {
  $parameter_name = $route_match
    ->getRouteObject()
    ->getOption('_og_entity_type_id');

  /** @var \Drupal\Core\Entity\EntityInterface $group */
  $group = $route_match
    ->getParameter($parameter_name);
  $entity_type_id = $group
    ->getEntityTypeId();

  // Get list from routes.
  $content = [];
  $event = new OgAdminRoutesEvent();
  $event = $this->eventDispatcher
    ->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, $event);
  foreach ($event
    ->getRoutes($entity_type_id) as $name => $info) {
    $route_name = "entity.{$entity_type_id}.og_admin_routes.{$name}";
    $parameters = [
      $entity_type_id => $group
        ->id(),
    ];

    // We don't use Url::fromRoute() here for the access check, as it will
    // prevent us from unit testing this method.
    if (!$this->accessManager
      ->checkNamedRoute($route_name, $parameters)) {

      // User doesn't have access to the route.
      continue;
    }
    $content[$name]['title'] = $info['title'];
    $content[$name]['description'] = $info['description'];
    $content[$name]['url'] = Url::fromRoute($route_name, $parameters);
  }
  if (!$content) {
    return [
      '#markup' => $this
        ->t('You do not have any administrative items.'),
    ];
  }
  return [
    'og_admin_routes' => [
      '#theme' => 'admin_block_content',
      '#content' => $content,
    ],
  ];
}