function EntityFieldManager::getExtraFields

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/EntityFieldManager.php \Drupal\Core\Entity\EntityFieldManager::getExtraFields()
  2. 10 core/lib/Drupal/Core/Entity/EntityFieldManager.php \Drupal\Core\Entity\EntityFieldManager::getExtraFields()
  3. 11.x core/lib/Drupal/Core/Entity/EntityFieldManager.php \Drupal\Core\Entity\EntityFieldManager::getExtraFields()

Overrides EntityFieldManagerInterface::getExtraFields

File

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

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 = $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];
}

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