You are here

class EntityActionsDeriver in Entity API 8

Derives local actions for entity types.

Hierarchy

Expanded class hierarchy of EntityActionsDeriver

1 string reference to 'EntityActionsDeriver'
entity.links.action.yml in ./entity.links.action.yml
entity.links.action.yml

File

src/Plugin/Derivative/EntityActionsDeriver.php, line 13

Namespace

Drupal\entity\Plugin\Derivative
View source
class EntityActionsDeriver extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs an entity local actions deriver.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    if (!$this->derivatives) {
      foreach ($this->entityTypeManager
        ->getDefinitions() as $entity_type_id => $entity_type) {
        $handlers = $entity_type
          ->getHandlerClasses();
        if (isset($handlers['local_action_provider'])) {
          foreach ($handlers['local_action_provider'] as $class) {

            /** @var \Drupal\entity\Menu\EntityLocalActionProviderInterface $handler */
            $handler = $this->entityTypeManager
              ->createHandlerInstance($class, $entity_type);
            $this->derivatives += $handler
              ->buildLocalActions($entity_type);
          }
        }
      }
    }
    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
EntityActionsDeriver::$entityTypeManager protected property The entity type manager.
EntityActionsDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
EntityActionsDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
EntityActionsDeriver::__construct public function Constructs an entity local actions deriver.