ActionManager.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Drupal\Core\Action;
  3. use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
  4. use Drupal\Core\Cache\CacheBackendInterface;
  5. use Drupal\Core\Extension\ModuleHandlerInterface;
  6. use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
  7. use Drupal\Core\Plugin\DefaultPluginManager;
  8. /**
  9. * Provides an Action plugin manager.
  10. *
  11. * @see \Drupal\Core\Annotation\Action
  12. * @see \Drupal\Core\Action\ActionInterface
  13. * @see \Drupal\Core\Action\ActionBase
  14. * @see plugin_api
  15. */
  16. class ActionManager extends DefaultPluginManager implements CategorizingPluginManagerInterface {
  17. use CategorizingPluginManagerTrait;
  18. /**
  19. * Constructs a new class instance.
  20. *
  21. * @param \Traversable $namespaces
  22. * An object that implements \Traversable which contains the root paths
  23. * keyed by the corresponding namespace to look for plugin implementations.
  24. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
  25. * Cache backend instance to use.
  26. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  27. * The module handler to invoke the alter hook with.
  28. */
  29. public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
  30. parent::__construct('Plugin/Action', $namespaces, $module_handler, 'Drupal\Core\Action\ActionInterface', 'Drupal\Core\Annotation\Action');
  31. $this->alterInfo('action_info');
  32. $this->setCacheBackend($cache_backend, 'action_info');
  33. }
  34. /**
  35. * Gets the plugin definitions for this entity type.
  36. *
  37. * @param string $type
  38. * The entity type name.
  39. *
  40. * @return array
  41. * An array of plugin definitions for this entity type.
  42. */
  43. public function getDefinitionsByType($type) {
  44. return array_filter($this->getDefinitions(), function ($definition) use ($type) {
  45. return $definition['type'] === $type;
  46. });
  47. }
  48. }