You are here

public function WebformElementManager::getGroupedDefinitions in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElementManager.php \Drupal\webform\Plugin\WebformElementManager::getGroupedDefinitions()

Gets sorted plugin definitions grouped by category.

In addition to grouping, both categories and its entries are sorted, whereas plugin definitions are sorted by label.

Parameters

array[]|null $definitions: (optional) The plugin definitions to group. If omitted, all plugin definitions are used.

Return value

array[] Keys are category names, and values are arrays of which the keys are plugin IDs and the values are plugin definitions.

Overrides CategorizingPluginManagerTrait::getGroupedDefinitions

File

src/Plugin/WebformElementManager.php, line 299

Class

WebformElementManager
Provides a plugin manager for webform element plugins.

Namespace

Drupal\webform\Plugin

Code

public function getGroupedDefinitions(array $definitions = NULL, $label_key = 'label') {

  /** @var \Drupal\Core\Plugin\CategorizingPluginManagerTrait|\Drupal\Component\Plugin\PluginManagerInterface $this */
  $definitions = $this
    ->getSortedDefinitions(isset($definitions) ? $definitions : $this
    ->getDefinitions(), $label_key);

  // Organize grouped definition with basic and advanced first and other last.
  $basic_category = (string) $this
    ->t('Basic elements');
  $advanced_category = (string) $this
    ->t('Advanced elements');
  $other_category = (string) $this
    ->t('Other elements');
  $grouped_definitions = [
    $basic_category => [],
    $advanced_category => [],
  ];
  foreach ($definitions as $id => $definition) {
    $grouped_definitions[(string) $definition['category']][$id] = $definition;
  }
  if (isset($grouped_definitions[''])) {
    $no_category = $grouped_definitions[''];
    unset($grouped_definitions['']);
    $grouped_definitions += [
      $other_category => $no_category,
    ];
  }
  return $grouped_definitions;
}