ActionListBuilder.php in Drupal 9
File
core/modules/action/src/ActionListBuilder.php
View source
<?php
namespace Drupal\action;
use Drupal\Core\Action\ActionManager;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ActionListBuilder extends ConfigEntityListBuilder {
protected $hasConfigurableActions = FALSE;
protected $actionManager;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ActionManager $action_manager) {
parent::__construct($entity_type, $storage);
$this->actionManager = $action_manager;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('plugin.manager.action'));
}
public function load() {
$entities = parent::load();
foreach ($entities as $entity) {
if ($entity
->isConfigurable()) {
$this->hasConfigurableActions = TRUE;
continue;
}
}
return $entities;
}
public function buildRow(EntityInterface $entity) {
$row['type'] = $entity
->getType();
$row['label'] = $entity
->label();
if ($this->hasConfigurableActions) {
$row += parent::buildRow($entity);
}
return $row;
}
public function buildHeader() {
$header = [
'type' => t('Action type'),
'label' => t('Label'),
] + parent::buildHeader();
return $header;
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = $entity
->isConfigurable() ? parent::getDefaultOperations($entity) : [];
if (isset($operations['edit'])) {
$operations['edit']['title'] = t('Configure');
}
return $operations;
}
public function render() {
$build['action_admin_manage_form'] = \Drupal::formBuilder()
->getForm('Drupal\\action\\Form\\ActionAdminManageForm');
$build['action_header']['#markup'] = '<h3>' . $this
->t('Available actions:') . '</h3>';
$build['action_table'] = parent::render();
if (!$this->hasConfigurableActions) {
unset($build['action_table']['table']['#header']['operations']);
}
return $build;
}
}