public function DatabaseStorageController::getFieldDefinitions

Implements \Drupal\Core\Entity\EntityStorageControllerInterface::getFieldDefinitions().

Overrides EntityStorageControllerInterface::getFieldDefinitions

1 call to DatabaseStorageController::getFieldDefinitions()
DatabaseStorageControllerNG::attachPropertyData in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Attaches property data in all languages for translatable properties.

File

drupal/core/lib/Drupal/Core/Entity/DatabaseStorageController.php, line 600
Contains \Drupal\Core\Entity\DatabaseStorageController.

Class

DatabaseStorageController
Defines a base entity controller class.

Namespace

Drupal\Core\Entity

Code

public function getFieldDefinitions(array $constraints) {
  if (!isset($this->entityFieldInfo)) {

    // First, try to load from cache.
    $cid = 'entity_field_definitions:' . $this->entityType . ':' . language(Language::TYPE_INTERFACE)->langcode;
    if ($cache = cache()
      ->get($cid)) {
      $this->entityFieldInfo = $cache->data;
    }
    else {
      $this->entityFieldInfo = array(
        'definitions' => $this
          ->baseFieldDefinitions(),
        // Contains definitions of optional (per-bundle) fields.
        'optional' => array(),
        // An array keyed by bundle name containing the optional fields added
        // by the bundle.
        'bundle map' => array(),
      );

      // Invoke hooks.
      $result = module_invoke_all($this->entityType . '_property_info');
      $this->entityFieldInfo = NestedArray::mergeDeep($this->entityFieldInfo, $result);
      $result = module_invoke_all('entity_field_info', $this->entityType);
      $this->entityFieldInfo = NestedArray::mergeDeep($this->entityFieldInfo, $result);
      $hooks = array(
        'entity_field_info',
        $this->entityType . '_property_info',
      );
      drupal_alter($hooks, $this->entityFieldInfo, $this->entityType);

      // Enforce fields to be multiple by default.
      foreach ($this->entityFieldInfo['definitions'] as &$definition) {
        $definition['list'] = TRUE;
      }
      foreach ($this->entityFieldInfo['optional'] as &$definition) {
        $definition['list'] = TRUE;
      }
      cache()
        ->set($cid, $this->entityFieldInfo, CacheBackendInterface::CACHE_PERMANENT, array(
        'entity_info' => TRUE,
      ));
    }
  }
  $bundle = !empty($constraints['Bundle']) ? $constraints['Bundle'] : FALSE;

  // Add in per-bundle fields.
  if (!isset($this->fieldDefinitions[$bundle])) {
    $this->fieldDefinitions[$bundle] = $this->entityFieldInfo['definitions'];
    if ($bundle && isset($this->entityFieldInfo['bundle map'][$bundle])) {
      $this->fieldDefinitions[$bundle] += array_intersect_key($this->entityFieldInfo['optional'], array_flip($this->entityFieldInfo['bundle map'][$bundle]));
    }
  }
  return $this->fieldDefinitions[$bundle];
}