Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FieldConfig.php

function 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\EntityBase::preSave().

File

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

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, modify or delete 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, modify or delete a configurable field of non-configurable field storage {$this->field_name}.");
        }
        $this->fieldStorage = $field_storage_definition;
    }
    return $this->fieldStorage;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal