function FieldConfig::getFieldStorageDefinition

Same name in other branches
  1. 8.9.x core/modules/field/src/Entity/FieldConfig.php \Drupal\field\Entity\FieldConfig::getFieldStorageDefinition()
  2. 10 core/modules/field/src/Entity/FieldConfig.php \Drupal\field\Entity\FieldConfig::getFieldStorageDefinition()
  3. 11.x core/modules/field/src/Entity/FieldConfig.php \Drupal\field\Entity\FieldConfig::getFieldStorageDefinition()

Overrides FieldDefinitionInterface::getFieldStorageDefinition

2 calls to FieldConfig::getFieldStorageDefinition()
FieldConfig::postCreate in core/modules/field/src/Entity/FieldConfig.php
Acts on a created entity before hooks are invoked.
FieldConfig::preSave in core/modules/field/src/Entity/FieldConfig.php
Overrides \Drupal\Core\Entity\Entity::preSave().

File

core/modules/field/src/Entity/FieldConfig.php, line 295

Class

FieldConfig
Defines the Field entity.

Namespace

Drupal\field\Entity

Code

public function getFieldStorageDefinition() {
    if (!$this->fieldStorage) {
        $field_storage_definition = NULL;
        $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($this->entity_type);
        if (isset($field_storage_definitions[$this->field_name])) {
            $field_storage_definition = $field_storage_definitions[$this->field_name];
        }
        elseif ($this->deleted) {
            $deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
            foreach ($deleted_storage_definitions as $deleted_storage_definition) {
                if ($deleted_storage_definition->getName() === $this->field_name) {
                    $field_storage_definition = $deleted_storage_definition;
                }
            }
        }
        if (!$field_storage_definition) {
            throw new FieldException("Attempted to create an instance of field with name {$this->field_name} on entity type {$this->entity_type} when the field storage does not exist.");
        }
        if (!$field_storage_definition instanceof FieldStorageConfigInterface) {
            throw new FieldException("Attempted to create a configurable field of non-configurable field storage {$this->field_name}.");
        }
        $this->fieldStorage = $field_storage_definition;
    }
    return $this->fieldStorage;
}

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