EntityFieldManager::getFieldDefinitions

public EntityFieldManager::getFieldDefinitions($entity_type_id, $bundle)

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 288

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];
}
doc_Drupal
2016-10-29 09:06:00
Comments
Leave a Comment

Please login to continue.