class ActionListController

Provides a listing of Actions.

Hierarchy

Expanded class hierarchy of ActionListController

File

drupal/core/modules/action/lib/Drupal/action/ActionListController.php, line 23
Contains \Drupal\action\ActionListController.

Namespace

Drupal\action
View source
class ActionListController extends ConfigEntityListController implements EntityControllerInterface {

  /**
   * @var bool
   */
  protected $hasConfigurableActions = FALSE;

  /**
   * The action plugin manager.
   *
   * @var \Drupal\Core\Action\ActionManager
   */
  protected $actionManager;

  /**
   * Constructs a new ActionListController object.
   *
   * @param string $entity_type
   *   The entity type.
   * @param array $entity_info
   *   An array of entity info for the entity type.
   * @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage
   *   The action storage controller.
   * @param \Drupal\Core\Action\ActionManager $action_manager
   *   The action plugin manager.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke hooks on.
   */
  public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ActionManager $action_manager, ModuleHandlerInterface $module_handler) {
    parent::__construct($entity_type, $entity_info, $storage, $module_handler);
    $this->actionManager = $action_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
    return new static($entity_type, $entity_info, $container
      ->get('plugin.manager.entity')
      ->getStorageController($entity_type), $container
      ->get('plugin.manager.action'), $container
      ->get('module_handler'));
  }

  /**
   * {@inheritdoc}
   */
  public function load() {
    $entities = parent::load();
    foreach ($entities as $entity) {
      if ($entity
        ->isConfigurable()) {
        $this->hasConfigurableActions = TRUE;
        continue;
      }
    }
    return $entities;
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row['type'] = $entity
      ->getType();
    $row['label'] = String::checkPlain($entity
      ->label());
    if ($this->hasConfigurableActions) {
      $row['operations']['data'] = $this
        ->buildOperations($entity);
    }
    return $row;
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header = array(
      'type' => t('Action type'),
      'label' => t('Label'),
      'operations' => t('Operations'),
    );
    return $header;
  }

  /**
   * {@inheritdoc}
   */
  public function getOperations(EntityInterface $entity) {
    $operations = array();
    if ($entity
      ->isConfigurable()) {
      $uri = $entity
        ->uri();
      $operations['edit'] = array(
        'title' => t('Configure'),
        'href' => $uri['path'],
        'options' => $uri['options'],
        'weight' => 10,
      );
      $operations['delete'] = array(
        'title' => t('Delete'),
        'href' => $uri['path'] . '/delete',
        'options' => $uri['options'],
        'weight' => 100,
      );
    }
    return $operations;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    $build['action_header']['#markup'] = '<h3>' . t('Available actions:') . '</h3>';
    $build['action_table'] = parent::render();
    if (!$this->hasConfigurableActions) {
      unset($build['action_table']['#header']['operations']);
    }
    $build['action_admin_manage_form'] = drupal_get_form(new ActionAdminManageForm($this->actionManager));
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActionListController::$actionManager protected property The action plugin manager.
ActionListController::$hasConfigurableActions protected property
ActionListController::buildHeader public function Builds the header row for the entity listing. Overrides EntityListController::buildHeader
ActionListController::buildRow public function Builds a row for an entity in the entity listing. Overrides EntityListController::buildRow
ActionListController::createInstance public static function Instantiates a new instance of this entity controller. Overrides EntityListController::createInstance
ActionListController::getOperations public function Overrides \Drupal\Core\Entity\EntityListController::getOperations(); Overrides ConfigEntityListController::getOperations
ActionListController::load public function Overrides Drupal\Core\Entity\EntityListController::load(). Overrides ConfigEntityListController::load
ActionListController::render public function Implements \Drupal\Core\Entity\EntityListControllerInterface::render(). Overrides EntityListController::render
ActionListController::__construct public function Constructs a new ActionListController object. Overrides EntityListController::__construct
EntityListController::$entityInfo protected property The entity info array.
EntityListController::$entityType protected property The entity type name.
EntityListController::$moduleHandler protected property The module handler to invoke hooks on.
EntityListController::$storage protected property The entity storage controller class.
EntityListController::buildOperations public function Builds a renderable list of operation links for the entity. 1
EntityListController::getStorageController public function Implements \Drupal\Core\Entity\EntityListControllerInterface::getStorageController(). Overrides EntityListControllerInterface::getStorageController