3 namespace Drupal\action;
5 use Drupal\Core\Action\ActionManager;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
8 use Drupal\Core\Entity\EntityStorageInterface;
9 use Drupal\Core\Entity\EntityTypeInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Defines a class to build a listing of action entities.
15 * @see \Drupal\system\Entity\Action
16 * @see action_entity_info()
18 class ActionListBuilder extends ConfigEntityListBuilder {
23 protected $hasConfigurableActions = FALSE;
26 * The action plugin manager.
28 * @var \Drupal\Core\Action\ActionManager
30 protected $actionManager;
33 * Constructs a new ActionListBuilder object.
35 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
36 * The entity type definition.
37 * @param \Drupal\Core\Entity\EntityStorageInterface $storage
39 * @param \Drupal\Core\Action\ActionManager $action_manager
40 * The action plugin manager.
42 public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ActionManager $action_manager) {
43 parent::__construct($entity_type, $storage);
45 $this->actionManager = $action_manager;
51 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
54 $container->get('entity.manager')->getStorage($entity_type->id()),
55 $container->get('plugin.manager.action')
62 public function load() {
63 $entities = parent::load();
64 foreach ($entities as $entity) {
65 if ($entity->isConfigurable()) {
66 $this->hasConfigurableActions = TRUE;
76 public function buildRow(EntityInterface $entity) {
77 $row['type'] = $entity->getType();
78 $row['label'] = $entity->label();
79 if ($this->hasConfigurableActions) {
80 $row += parent::buildRow($entity);
88 public function buildHeader() {
90 'type' => t('Action type'),
91 'label' => t('Label'),
92 ] + parent::buildHeader();
99 public function getDefaultOperations(EntityInterface $entity) {
100 $operations = $entity->isConfigurable() ? parent::getDefaultOperations($entity) : [];
101 if (isset($operations['edit'])) {
102 $operations['edit']['title'] = t('Configure');
110 public function render() {
111 $build['action_admin_manage_form'] = \Drupal::formBuilder()->getForm('Drupal\action\Form\ActionAdminManageForm');
112 $build['action_header']['#markup'] = '<h3>' . $this->t('Available actions:') . '</h3>';
113 $build['action_table'] = parent::render();
114 if (!$this->hasConfigurableActions) {
115 unset($build['action_table']['table']['#header']['operations']);