You are here

public function EntityFieldManager::getFieldDefinitions in Zircon Profile 8

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

Gets the field definitions for a specific bundle.

Parameters

string $entity_type_id: The entity type ID. Only entity types that implement \Drupal\Core\Entity\FieldableEntityInterface are supported.

string $bundle: The bundle.

Return value

\Drupal\Core\Field\FieldDefinitionInterface[] The array of field definitions for the bundle, keyed by field name.

Overrides EntityFieldManagerInterface::getFieldDefinitions

File

core/lib/Drupal/Core/Entity/EntityFieldManager.php, line 293
Contains \Drupal\Core\Entity\EntityFieldManager.

Class

EntityFieldManager
Manages the discovery of entity fields.

Namespace

Drupal\Core\Entity

Code

public function getFieldDefinitions($entity_type_id, $bundle) {
  if (!isset($this->fieldDefinitions[$entity_type_id][$bundle])) {
    $base_field_definitions = $this
      ->getBaseFieldDefinitions($entity_type_id);

    // Not prepared, try to load from cache.
    $cid = 'entity_bundle_field_definitions:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager
      ->getCurrentLanguage()
      ->getId();
    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] = array_replace($base_field_definitions, $bundle_field_definitions);
  }
  return $this->fieldDefinitions[$entity_type_id][$bundle];
}