You are here

protected function EntityCreateController::loadBundleDescriptions in Entity API 8.0

Expands the bundle information with descriptions, if known.

Parameters

array $bundles: An array of bundle information.

string $bundle_type: The id of the bundle entity type.

Return value

array The expanded array of bundle information.

1 call to EntityCreateController::loadBundleDescriptions()
EntityCreateController::addPage in src/Controller/EntityCreateController.php
Displays add links for the available bundles.

File

src/Controller/EntityCreateController.php, line 197
Contains \Drupal\entity\Controller\EntityCreateController.

Class

EntityCreateController
A generic controller for creating entities.

Namespace

Drupal\entity\Controller

Code

protected function loadBundleDescriptions(array $bundles, $bundle_type) {

  // Ensure the presence of the description key.
  foreach ($bundles as $bundle_name => &$bundle_info) {
    $bundle_info['description'] = '';
  }

  // Only bundles provided by entity types have descriptions.
  if (empty($bundle_type)) {
    return $bundles;
  }
  $bundle_entity_type = $this
    ->entityTypeManager()
    ->getDefinition($bundle_type);
  if (!$bundle_entity_type
    ->isSubclassOf('\\Drupal\\entity\\Entity\\EntityDescriptionInterface')) {
    return $bundles;
  }
  $bundle_names = array_keys($bundles);
  $bundle_entities = $this->entityTypeManager
    ->getStorage($bundle_type)
    ->loadMultiple($bundle_names);
  foreach ($bundles as $bundle_name => &$bundle_info) {
    if (isset($bundle_entities[$bundle_name])) {
      $bundle_info['description'] = $bundle_entities[$bundle_name]
        ->getDescription();
    }
  }
  return $bundles;
}