function EntityFieldManager::getFieldDefinitions

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

Overrides EntityFieldManagerInterface::getFieldDefinitions

File

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

Class

EntityFieldManager
Manages the discovery of entity fields.

Namespace

Drupal\Core\Entity

Code

public function getFieldDefinitions($entity_type_id, $bundle) {
    $langcode = $this->languageManager
        ->getCurrentLanguage()
        ->getId();
    if (!isset($this->fieldDefinitions[$entity_type_id][$bundle][$langcode])) {
        $base_field_definitions = $this->getBaseFieldDefinitions($entity_type_id);
        // Not prepared, try to load from cache.
        $cid = 'entity_bundle_field_definitions:' . $entity_type_id . ':' . $bundle . ':' . $langcode;
        if ($cache = $this->cacheGet($cid)) {
            $bundle_field_definitions = $cache->data;
        }
        else {
            // Rebuild the definitions and put it into the cache.
            $bundle_field_definitions = $this->buildBundleFieldDefinitions($entity_type_id, $bundle, $base_field_definitions);
            $this->cacheSet($cid, $bundle_field_definitions, Cache::PERMANENT, [
                'entity_types',
                'entity_field_info',
            ]);
        }
        // Field definitions consist of the bundle specific overrides and the
        // base fields, merge them together. Use array_replace() to replace base
        // fields with by bundle overrides and keep them in order, append
        // additional by bundle fields.
        $this->fieldDefinitions[$entity_type_id][$bundle][$langcode] = array_replace($base_field_definitions, $bundle_field_definitions);
    }
    return $this->fieldDefinitions[$entity_type_id][$bundle][$langcode];
}

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