function FieldTypePluginManager::getGroupedDefinitions

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Field/FieldTypePluginManager.php \Drupal\Core\Field\FieldTypePluginManager::getGroupedDefinitions()

Gets sorted field type 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.

string $label_key: (optional) The array key to use as the label of the field type.

string $category_label_key: (optional) The array key to use as the label of the category.

Return value

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

File

core/lib/Drupal/Core/Field/FieldTypePluginManager.php, line 179

Class

FieldTypePluginManager
Plugin manager for 'field type' plugins.

Namespace

Drupal\Core\Field

Code

public function getGroupedDefinitions(array $definitions = NULL, $label_key = 'label', $category_label_key = 'label') {
    $grouped_categories = $this->getGroupedDefinitionsTrait($definitions, $label_key);
    $category_info = $this->fieldTypeCategoryManager
        ->getDefinitions();
    // Ensure that all the referenced categories exist.
    foreach ($grouped_categories as $group => $definitions) {
        if (!isset($category_info[$group])) {
            assert(FALSE, "\"{$group}\" must be defined in MODULE_NAME.field_type_categories.yml");
            if (!isset($grouped_categories[FieldTypeCategoryManagerInterface::FALLBACK_CATEGORY])) {
                $grouped_categories[FieldTypeCategoryManagerInterface::FALLBACK_CATEGORY] = [];
            }
            $grouped_categories[FieldTypeCategoryManagerInterface::FALLBACK_CATEGORY] += $definitions;
            unset($grouped_categories[$group]);
        }
    }
    $normalized_grouped_categories = [];
    foreach ($grouped_categories as $group => $definitions) {
        $normalized_grouped_categories[(string) $category_info[$group][$category_label_key]] = $definitions;
    }
    return $normalized_grouped_categories;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.