OgAdminRoutesController.php in Organic groups 8
File
src/Controller/OgAdminRoutesController.php
View source
<?php
declare (strict_types=1);
namespace Drupal\og\Controller;
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\og\Event\OgAdminRoutesEvent;
use Drupal\og\Event\OgAdminRoutesEventInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OgAdminRoutesController extends ControllerBase {
protected $eventDispatcher;
protected $accessManager;
public function __construct(ContainerAwareEventDispatcher $event_dispatcher, AccessManagerInterface $access_manager) {
$this->eventDispatcher = $event_dispatcher;
$this->accessManager = $access_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('event_dispatcher'), $container
->get('access_manager'));
}
public function overview(RouteMatchInterface $route_match) {
$parameter_name = $route_match
->getRouteObject()
->getOption('_og_entity_type_id');
$group = $route_match
->getParameter($parameter_name);
$entity_type_id = $group
->getEntityTypeId();
$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(),
];
if (!$this->accessManager
->checkNamedRoute($route_name, $parameters)) {
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,
],
];
}
}