You are here

class ListPluginTypes in Plugin 8.2

Handles the "list plugin types" route.

Hierarchy

Expanded class hierarchy of ListPluginTypes

1 file declares its use of ListPluginTypes
ListPluginTypesTest.php in tests/src/Unit/Controller/ListPluginTypesTest.php

File

src/Controller/ListPluginTypes.php, line 14

Namespace

Drupal\plugin\Controller
View source
class ListPluginTypes extends ListBase {

  /**
   * The plugin type manager.
   *
   * @var \Drupal\plugin\PluginType\PluginTypeManagerInterface
   */
  protected $pluginTypeManager;

  /**
   * Constructs a new instance.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translator.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\plugin\PluginType\PluginTypeManagerInterface
   *   The plugin type manager.
   */
  public function __construct(TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, PluginTypeManagerInterface $plugin_type_manager) {
    parent::__construct($string_translation, $module_handler);
    $this->pluginTypeManager = $plugin_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('string_translation'), $container
      ->get('module_handler'), $container
      ->get('plugin.plugin_type_manager'));
  }

  /**
   * Handles the route.
   *
   * @return mixed[]
   *   A render array.
   */
  public function execute() {
    $build = [
      '#empty' => $this
        ->t('There are no available plugin types.'),
      '#header' => [
        $this
          ->t('Type'),
        $this
          ->t('Description'),
        $this
          ->t('Provider'),
        $this
          ->t('Operations'),
      ],
      '#type' => 'table',
    ];
    $plugin_types = $this->pluginTypeManager
      ->getPluginTypes();
    uasort($plugin_types, function (PluginTypeInterface $plugin_type_a, PluginTypeInterface $plugin_type_b) {
      return strnatcasecmp($plugin_type_a
        ->getLabel(), $plugin_type_b
        ->getLabel());
    });
    foreach ($plugin_types as $plugin_type_id => $plugin_type) {
      $operations_provider = $plugin_type
        ->getOperationsProvider();
      $operations = $operations_provider ? $operations_provider
        ->getOperations($plugin_type_id) : [];
      $build[$plugin_type_id]['label'] = [
        '#markup' => $plugin_type
          ->getLabel(),
      ];
      $build[$plugin_type_id]['description'] = [
        '#markup' => $plugin_type
          ->getDescription(),
      ];
      $build[$plugin_type_id]['provider'] = [
        '#markup' => $this
          ->getProviderLabel($plugin_type
          ->getProvider()),
      ];
      $build[$plugin_type_id]['operations'] = [
        '#links' => $operations,
        '#type' => 'operations',
      ];
    }
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ListBase::$moduleHandler protected property The module handler.
ListBase::getProviderLabel protected function Gets the human-readable provider label.
ListPluginTypes::$pluginTypeManager protected property The plugin type manager.
ListPluginTypes::create public static function Instantiates a new instance of this class. Overrides ListBase::create
ListPluginTypes::execute public function Handles the route.
ListPluginTypes::__construct public function Constructs a new instance. Overrides ListBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.