public function PluginHelperTrait::getGroupedDefinitions in Layout Builder Restrictions 8.2
Method to categorize blocks in a multilingual-friendly way.
This is based on CategorizingPluginManagerTrait::getGroupedDefinitions.
Parameters
array $definitions: The definitions as provided by the Block Plugin Manager.
string $label_key: The key to use if a block does not have a category defined.
Return value
array Definitions grouped by untranslated category.
1 call to PluginHelperTrait::getGroupedDefinitions()
- PluginHelperTrait::getDefinitionsByUntranslatedCategory in src/
Traits/ PluginHelperTrait.php - Generate a categorized list of blocks, based on the untranslated category.
File
- src/
Traits/ PluginHelperTrait.php, line 127
Class
- PluginHelperTrait
- Methods to help Layout Builder Restrictions plugins.
Namespace
Drupal\layout_builder_restrictions\TraitsCode
public function getGroupedDefinitions(array $definitions = NULL, $label_key = 'label') {
$definitions = $this
->getSortedDefinitions($definitions, $label_key);
$grouped_definitions = [];
foreach ($definitions as $id => $definition) {
// If the block category is a translated string, get the
// untranslated equivalent to create an unchanging category ID, not
// affected by multilingual translations.
$category = $this
->getUntranslatedCategory($definition['category']);
if (!isset($grouped_definitions[$category])) {
$grouped_definitions[$category]['label'] = $category;
// Also add the translated string in there, to use for the display of
// the categories.
$grouped_definitions[$category]['translated_label'] = (string) $definition['category'];
}
$grouped_definitions[$category]['definitions'][$id] = $definition;
}
return $grouped_definitions;
}