You are here

public function EntityFieldManager::getExtraFields in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityFieldManager.php \Drupal\Core\Entity\EntityFieldManager::getExtraFields()

Gets the "extra fields" for a bundle.

Parameters

string $entity_type_id: The entity type ID.

string $bundle: The bundle name.

Return value

array A nested array of 'pseudo-field' elements. Each list is nested within the following keys: entity type, bundle name, context (either 'form' or 'display'). The keys are the name of the elements as appearing in the renderable array (either the entity form or the displayed entity). The value is an associative array:

  • label: The human readable name of the element. Make sure you sanitize this appropriately.
  • description: A short description of the element contents.
  • weight: The default weight of the element.
  • visible: (optional) The default visibility of the element. Defaults to TRUE.
  • edit: (optional) String containing markup (normally a link) used as the element's 'edit' operation in the administration interface. Only for 'form' context.
  • delete: (optional) String containing markup (normally a link) used as the element's 'delete' operation in the administration interface. Only for 'form' context.

Overrides EntityFieldManagerInterface::getExtraFields

File

core/lib/Drupal/Core/Entity/EntityFieldManager.php, line 627

Class

EntityFieldManager
Manages the discovery of entity fields.

Namespace

Drupal\Core\Entity

Code

public function getExtraFields($entity_type_id, $bundle) {

  // Read from the "static" cache.
  if (isset($this->extraFields[$entity_type_id][$bundle])) {
    return $this->extraFields[$entity_type_id][$bundle];
  }

  // Read from the persistent cache. Since hook_entity_extra_field_info() and
  // hook_entity_extra_field_info_alter() might contain t() calls, we cache
  // per language.
  $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager
    ->getCurrentLanguage()
    ->getId();
  $cached = $this
    ->cacheGet($cache_id);
  if ($cached) {
    $this->extraFields[$entity_type_id][$bundle] = $cached->data;
    return $this->extraFields[$entity_type_id][$bundle];
  }
  $extra = $this->moduleHandler
    ->invokeAll('entity_extra_field_info');
  $this->moduleHandler
    ->alter('entity_extra_field_info', $extra);
  $info = isset($extra[$entity_type_id][$bundle]) ? $extra[$entity_type_id][$bundle] : [];
  $info += [
    'form' => [],
    'display' => [],
  ];

  // Store in the 'static' and persistent caches.
  $this->extraFields[$entity_type_id][$bundle] = $info;
  $this
    ->cacheSet($cache_id, $info, Cache::PERMANENT, [
    'entity_field_info',
  ]);
  return $this->extraFields[$entity_type_id][$bundle];
}