function EntityController::loadBundleDescriptions

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Controller/EntityController.php \Drupal\Core\Entity\Controller\EntityController::loadBundleDescriptions()
  2. 8.9.x core/lib/Drupal/Core/Entity/Controller/EntityController.php \Drupal\Core\Entity\Controller\EntityController::loadBundleDescriptions()
  3. 10 core/lib/Drupal/Core/Entity/Controller/EntityController.php \Drupal\Core\Entity\Controller\EntityController::loadBundleDescriptions()

Expands the bundle information with descriptions, if known.

Also sorts the bundles before adding the bundle descriptions. Sorting is being done here to avoid having to load bundle entities multiple times.

Parameters

array $bundles: An array of bundle information.

\Drupal\Core\Entity\EntityTypeInterface $bundle_entity_type: The bundle entity type definition.

Return value

array An array of sorted bundle information including bundle descriptions.

1 call to EntityController::loadBundleDescriptions()
EntityController::addPage in core/lib/Drupal/Core/Entity/Controller/EntityController.php
Displays add links for the available bundles.

File

core/lib/Drupal/Core/Entity/Controller/EntityController.php, line 349

Class

EntityController
Provides the add-page and title callbacks for entities.

Namespace

Drupal\Core\Entity\Controller

Code

protected function loadBundleDescriptions(array $bundles, EntityTypeInterface $bundle_entity_type) {
  if (!$bundle_entity_type->entityClassImplements(EntityDescriptionInterface::class)) {
    return $bundles;
  }
  $bundle_names = array_keys($bundles);
  $storage = $this->entityTypeManager
    ->getStorage($bundle_entity_type->id());
  /** @var \Drupal\Core\Entity\EntityDescriptionInterface[] $bundle_entities */
  $bundle_entities = $storage->loadMultiple($bundle_names);
  uasort($bundle_entities, [
    $bundle_entity_type->getClass(),
    'sort',
  ]);
  $bundles = array_replace($bundle_entities, $bundles);
  foreach ($bundles as $bundle_name => &$bundle_info) {
    if (isset($bundle_entities[$bundle_name])) {
      $bundle_info['description'] = $bundle_entities[$bundle_name]->getDescription();
    }
  }
  return $bundles;
}

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