3 namespace Drupal\workflows;
5 use Drupal\Component\Plugin\PluginManagerInterface;
6 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Entity\EntityStorageInterface;
9 use Drupal\Core\Entity\EntityTypeInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Provides a listing of Workflow entities.
15 class WorkflowListBuilder extends ConfigEntityListBuilder {
18 * The workflow type plugin manager.
20 * @var \Drupal\Component\Plugin\PluginManagerInterface
22 protected $workflowTypeManager;
27 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
30 $container->get('entity_type.manager')->getStorage($entity_type->id()),
31 $container->get('plugin.manager.workflows.type')
36 * Constructs a new WorkflowListBuilder object.
38 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
39 * The entity type definition.
40 * @param \Drupal\Core\Entity\EntityStorageInterface $storage
41 * The entity storage class.
42 * @param \Drupal\Component\Plugin\PluginManagerInterface $workflow_type_manager
43 * The workflow type plugin manager.
45 public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, PluginManagerInterface $workflow_type_manager) {
46 parent::__construct($entity_type, $storage);
47 $this->workflowTypeManager = $workflow_type_manager;
53 public function getFormId() {
54 return 'workflow_admin_overview_form';
60 public function buildHeader() {
61 $header['label'] = $this->t('Workflow');
62 $header['type'] = $this->t('Type');
63 $header['states'] = $this->t('States');
65 return $header + parent::buildHeader();
71 public function buildRow(EntityInterface $entity) {
72 /** @var \Drupal\workflows\WorkflowInterface $entity */
73 $row['label'] = $entity->label();
75 $row['type']['data'] = [
76 '#markup' => $entity->getTypePlugin()->label()
79 $items = array_map([State::class, 'labelCallback'], $entity->getTypePlugin()->getStates());
80 $row['states']['data'] = [
81 '#theme' => 'item_list',
82 '#context' => ['list_style' => 'comma-list'],
86 return $row + parent::buildRow($entity);
92 public function render() {
93 $build = parent::render();
94 $workflow_types_count = count($this->workflowTypeManager->getDefinitions());
95 if ($workflow_types_count === 0) {
96 $build['table']['#empty'] = $this->t('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the Content Moderation module provides a workflow type that enables workflows for content entities.');