public function ListPlugins::execute in Plugin 8.2
Handles the route.
Parameters
\Drupal\plugin\PluginType\PluginTypeInterface $plugin_type: The plugin type.
Return value
mixed[]|\Symfony\Component\HttpFoundation\Response A render array or a Symfony response.
1 string reference to 'ListPlugins::execute'
File
- src/
Controller/ ListPlugins.php, line 72
Class
- ListPlugins
- Handles the "list plugin" route.
Namespace
Drupal\plugin\ControllerCode
public function execute(PluginTypeInterface $plugin_type) {
$build = [
'#empty' => $this
->t('There are no available plugins.'),
'#header' => [
$this
->t('Plugin'),
$this
->t('ID'),
$this
->t('Description'),
$this
->t('Provider'),
$this
->t('Operations'),
],
'#type' => 'table',
];
$plugin_discovery = new TypedDefinitionEnsuringPluginDiscoveryDecorator($plugin_type);
/** @var \Drupal\plugin\PluginDefinition\PluginDefinitionInterface[] $plugin_definitions */
$plugin_definitions = $plugin_discovery
->getDefinitions();
ksort($plugin_definitions);
foreach ($plugin_definitions as $plugin_definition) {
$operations = [];
if ($plugin_definition instanceof PluginOperationsProviderDefinitionInterface) {
$operations_provider_class = $plugin_definition
->getOperationsProviderClass();
if ($operations_provider_class) {
/** @var \Drupal\plugin\PluginOperationsProviderInterface $operations_provider */
$operations_provider = $this->classResolver
->getInstanceFromDefinition($operations_provider_class);
$operations = $operations_provider
->getOperations($plugin_definition
->getId());
}
}
$build[$plugin_definition
->getId()] = [
'label' => [
'#markup' => $plugin_definition instanceof PluginLabelDefinitionInterface ? (string) $plugin_definition
->getLabel() : NULL,
],
'id' => [
'#markup' => $plugin_definition
->getId(),
'#prefix' => '<code>',
'#suffix' => '</code>',
],
'description' => [
'#markup' => $plugin_definition instanceof PluginDescriptionDefinitionInterface ? (string) $plugin_definition
->getDescription() : NULL,
],
'provider' => [
'#markup' => $this
->getProviderLabel($plugin_definition
->getProvider()),
],
'operations' => [
'#links' => $operations,
'#type' => 'operations',
],
];
}
return $build;
}