You are here

public function ListPluginTypes::execute in Plugin 8.2

Handles the route.

Return value

mixed[] A render array.

1 string reference to 'ListPluginTypes::execute'
plugin.routing.yml in ./plugin.routing.yml
plugin.routing.yml

File

src/Controller/ListPluginTypes.php, line 51

Class

ListPluginTypes
Handles the "list plugin types" route.

Namespace

Drupal\plugin\Controller

Code

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;
}