commands-1.x-dev/modules/tasks/src/TaskTypeListBuilder.php

modules/tasks/src/TaskTypeListBuilder.php
<?php

declare(strict_types=1);

namespace Drupal\tasks;

use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;

/**
 * Defines a class to build a listing of tasks type entities.
 *
 * @see \Drupal\tasks\Entity\TaskType
 */
final class TaskTypeListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['title'] = $this->t('Type');
    $header['description'] = $this->t('Description');

    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
//    $plugin = $entity->getPlugin();
    $row['title'] = [
      'data' => $entity->label(),
      'class' => ['menu-label'],
    ];

    $row['description'] = $entity->description();

    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function loadPlugins() {
    $type = \Drupal::service('plugin.manager.task_type');
    $plugins = $type->getDefinitions();
    foreach ($plugins as $plugin_id => &$plugin) {
      $plugin = $type->createInstance($plugin_id);
    }
    return $plugins;
  }

  /**
   * Render a row of the "Disabled commands"
   */
  public function buildPluginRow($plugin) {
    $row['title'] = [
      'data' => $plugin->label(),
      'class' => ['menu-label'],
    ];
    $row['description'] = $plugin->description();
    $row['operations'] = Link::createFromRoute(t('Enable'), 'entity.task_type.type_add', [
      'plugin'=> $plugin->getPluginId(),
    ]);

    return $row;
  }

  /**
   * Render a list of command plugins that do not have bundles.
   * @return array
   */
  public function renderDisabled() {
    $build['title'] = [
      '#type' => 'html_tag',
      '#tag' => 'h3',
      '#value' => $this->t('Disabled task types'),
    ];
    $build['table'] = [
      '#type' => 'table',
      '#header' => $this->buildHeader(),
      '#title' => t('Disabled task types'),
      '#title_display' => 'before',
      '#rows' => [],
      '#empty' => $this->t('There are no disabled @label.', ['@label' => $this->entityType->getPluralLabel()]),
      '#cache' => [
        'contexts' => $this->entityType->getListCacheContexts(),
        'tags' => $this->entityType->getListCacheTags(),
      ],
    ];
    foreach ($this->loadPlugins() as $plugin_id => $plugin) {
      if (!in_array($plugin->getPluginId(), $this->getEntityIds()) && $row = $this->buildPluginRow($plugin)) {
        $build['table']['#rows'][$plugin->getPluginId()] = $row;
      }
    }

    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    $build = parent::render();

    $build['disabled'] = $this->renderDisabled();


    return $build;
  }


}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc