You are here

public function FieldConfig::getFieldStorageDefinition in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field/src/Entity/FieldConfig.php \Drupal\field\Entity\FieldConfig::getFieldStorageDefinition()

Returns the field storage definition.

Return value

\Drupal\Core\Field\FieldStorageDefinitionInterface The field storage definition.

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("Attempt to create a field {$this->field_name} that does not exist on entity type {$this->entity_type}.");
    }
    if (!$field_storage_definition instanceof FieldStorageConfigInterface) {
      throw new FieldException("Attempt to create a configurable field of non-configurable field storage {$this->field_name}.");
    }
    $this->fieldStorage = $field_storage_definition;
  }
  return $this->fieldStorage;
}