protected function PluginHierarchyTrait::buildPluginHierarchy in Plugin 8.2
Returns a hierarchical plugin representation.
Parameters
\Drupal\plugin\PluginDiscovery\TypedDiscoveryInterface $plugin_discovery: The typed plugin discovery.
Return value
array[] A possibly infinitely nested associative array. Keys are plugin IDs and values are arrays of similar structure as this method's return value.
1 call to PluginHierarchyTrait::buildPluginHierarchy()
- SelectList::buildSelector in src/
Plugin/ Plugin/ PluginSelector/ SelectList.php - Builds the form elements for the actual plugin selector.
File
- src/
PluginHierarchyTrait.php, line 25
Class
- PluginHierarchyTrait
- Supports handling hierarchical plugins.
Namespace
Drupal\pluginCode
protected function buildPluginHierarchy(TypedDiscoveryInterface $plugin_discovery) {
$parents = [];
$children = [];
$definitions = $plugin_discovery
->getDefinitions();
uasort($definitions, function (PluginDefinitionInterface $definition_a, PluginDefinitionInterface $definition_b) {
$label_a = $definition_a instanceof PluginLabelDefinitionInterface ? $definition_a
->getLabel() : $definition_a
->getId();
$label_b = $definition_b instanceof PluginLabelDefinitionInterface ? $definition_b
->getLabel() : $definition_b
->getId();
return strcmp($label_a, $label_b);
});
foreach ($definitions as $plugin_id => $plugin_definition) {
if ($plugin_definition instanceof PluginHierarchyDefinitionInterface && $plugin_definition
->getParentId()) {
$children[$plugin_definition
->getParentId()][] = $plugin_id;
}
else {
$parents[] = $plugin_id;
}
}
return $this
->buildPluginHierarchyLevel($parents, $children);
}