ResetAccessRules.php in RNG - Events and Registrations 3.x
File
src/Plugin/Menu/LocalAction/ResetAccessRules.php
View source
<?php
namespace Drupal\rng\Plugin\Menu\LocalAction;
use Drupal\Core\Menu\LocalActionDefault;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\rng\EventManagerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\HttpFoundation\Request;
class ResetAccessRules extends LocalActionDefault {
use StringTranslationTrait;
protected $eventManager;
protected $currentRoute;
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, EventManagerInterface $event_manager, RouteMatchInterface $current_route) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider);
$this->eventManager = $event_manager;
$this->currentRoute = $current_route;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('router.route_provider'), $container
->get('rng.event_manager'), $container
->get('current_route_match'));
}
public function getTitle(Request $request = NULL) {
$route = $this->routeProvider
->getRouteByName($this
->getRouteName());
$param = $route
->getDefault('event');
if ($event = $this->currentRoute
->getParameter($param)) {
if ($this->eventManager
->getMeta($event)
->isDefaultRules('rng_event.register')) {
return $this
->t('Customize access rules');
}
else {
return $this
->t('Reset access rules to site default');
}
}
}
}