You are here

class LocalActions in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/LocalActions.php \Drupal\rng\Plugin\Derivative\LocalActions
  2. 3.x src/Plugin/Derivative/LocalActions.php \Drupal\rng\Plugin\Derivative\LocalActions

Provides dynamic local actions for RNG.

Hierarchy

Expanded class hierarchy of LocalActions

1 string reference to 'LocalActions'
rng.links.action.yml in ./rng.links.action.yml
rng.links.action.yml

File

src/Plugin/Derivative/LocalActions.php, line 17

Namespace

Drupal\rng\Plugin\Derivative
View source
class LocalActions extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * The RNG event manager.
   *
   * @var \Drupal\rng\EventManagerInterface
   */
  protected $eventManager;

  /**
   * Constructs a LocalTasks object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   *   The route provider.
   * @param \Drupal\rng\EventManagerInterface $event_manager
   *   The RNG event manager.
   */
  public function __construct(EntityManagerInterface $entity_manager, RouteProviderInterface $route_provider, EventManagerInterface $event_manager) {
    $this->entityManager = $entity_manager;
    $this->routeProvider = $route_provider;
    $this->eventManager = $event_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity.manager'), $container
      ->get('router.route_provider'), $container
      ->get('rng.event_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];

    /** @var \Drupal\rng\Entity\EventType[] $event_types */
    foreach ($this->eventManager
      ->getEventTypes() as $entity_type => $event_types) {
      $cache_tags = $this->entityManager
        ->getDefinition($entity_type)
        ->getListCacheTags();
      foreach ($event_types as $event_type) {
        $cache_tags = Cache::mergeTags($cache_tags, $event_type
          ->getCacheTags());
      }

      // Only need one set of actions per entity type.
      $this->derivatives["rng.event.{$entity_type}.event.access.reset"] = array(
        'title' => $this
          ->t('Reset/customize access rules'),
        'route_name' => "rng.event.{$entity_type}.access.reset",
        'class' => '\\Drupal\\rng\\Plugin\\Menu\\LocalAction\\ResetAccessRules',
        'appears_on' => array(
          "rng.event.{$entity_type}.access",
        ),
        'cache_tags' => $cache_tags,
      );
      $this->derivatives["rng.event.{$entity_type}.event.message.add"] = array(
        'title' => $this
          ->t('Add message'),
        'route_name' => "rng.event.{$entity_type}.messages.add",
        'appears_on' => array(
          "rng.event.{$entity_type}.messages",
        ),
        'cache_tags' => $cache_tags,
      );
      $this->derivatives["rng.event.{$entity_type}.event.group.add"] = array(
        'title' => $this
          ->t('Add group'),
        'route_name' => "rng.event.{$entity_type}.group.add",
        'appears_on' => array(
          "rng.event.{$entity_type}.group.list",
        ),
        'cache_tags' => $cache_tags,
      );
    }
    foreach ($this->derivatives as &$entry) {
      $entry += $base_plugin_definition;
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
LocalActions::$entityManager protected property The entity manager.
LocalActions::$eventManager protected property The RNG event manager.
LocalActions::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
LocalActions::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
LocalActions::__construct public function Constructs a LocalTasks object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.