class FieldStorageConfig

Same name in other branches
  1. 9 core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig
  2. 8.9.x core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig
  3. 11.x core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig

Defines the Field storage configuration entity.

Plugin annotation


@ConfigEntityType(
  id = "field_storage_config",
  label = @Translation("Field storage"),
  label_collection = @Translation("Field storages"),
  label_singular = @Translation("field storage"),
  label_plural = @Translation("field storages"),
  label_count = @PluralTranslation(
    singular = "@count field storage",
    plural = "@count field storages",
  ),
  handlers = {
    "access" = "Drupal\field\FieldStorageConfigAccessControlHandler",
    "storage" = "Drupal\field\FieldStorageConfigStorage"
  },
  config_prefix = "storage",
  entity_keys = {
    "id" = "id",
    "label" = "id"
  },
  config_export = {
    "id",
    "field_name",
    "entity_type",
    "type",
    "settings",
    "module",
    "locked",
    "cardinality",
    "translatable",
    "indexes",
    "persist_with_no_fields",
    "custom_storage",
  },
  constraints = {
    "ImmutableProperties" = {"id", "entity_type", "field_name", "type"},
  }
)

Hierarchy

Expanded class hierarchy of FieldStorageConfig

312 files declare their use of FieldStorageConfig
ArbitraryRebuildTest.php in core/modules/system/tests/src/Functional/Form/ArbitraryRebuildTest.php
BlockContentFieldFilterTest.php in core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php
block_content.module in core/modules/block_content/block_content.module
Allows the creation of content blocks through the user interface.
BooleanFieldTest.php in core/modules/field/tests/src/Functional/Boolean/BooleanFieldTest.php
BooleanFormatterSettingsTest.php in core/modules/field/tests/src/Functional/Boolean/BooleanFormatterSettingsTest.php

... See full list

File

core/modules/field/src/Entity/FieldStorageConfig.php, line 57

Namespace

Drupal\field\Entity
View source
class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigInterface {
    
    /**
     * The maximum length of the field name, in characters.
     *
     * For fields created through Field UI, this includes the 'field_' prefix.
     */
    const NAME_MAX_LENGTH = 32;
    
    /**
     * The field ID.
     *
     * The ID consists of 2 parts: the entity type and the field name.
     *
     * Example: node.body, user.field_main_image.
     *
     * @var string
     */
    protected $id;
    
    /**
     * The field name.
     *
     * This is the name of the property under which the field values are placed in
     * an entity: $entity->{$field_name}. The maximum length is
     * Field:NAME_MAX_LENGTH.
     *
     * Example: body, field_main_image.
     *
     * @var string
     */
    protected $field_name;
    
    /**
     * The name of the entity type the field can be attached to.
     *
     * @var string
     */
    protected $entity_type;
    
    /**
     * The field type.
     *
     * Example: text, integer.
     *
     * @var string
     */
    protected $type;
    
    /**
     * The name of the module that provides the field type.
     *
     * @var string
     */
    protected $module;
    
    /**
     * Field-type specific settings.
     *
     * An array of key/value pairs, The keys and default values are defined by the
     * field type.
     *
     * @var array
     */
    protected $settings = [];
    
    /**
     * The field cardinality.
     *
     * The maximum number of values the field can hold. Possible values are
     * positive integers or
     * FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED. Defaults to 1.
     *
     * @var int
     */
    protected $cardinality = 1;
    
    /**
     * Flag indicating whether the field is translatable.
     *
     * Defaults to TRUE.
     *
     * @var bool
     */
    protected $translatable = TRUE;
    
    /**
     * Flag indicating whether the field is available for editing.
     *
     * If TRUE, some actions not available though the UI (but are still possible
     * through direct API manipulation):
     * - field settings cannot be changed,
     * - new fields cannot be created
     * - existing fields cannot be deleted.
     * Defaults to FALSE.
     *
     * @var bool
     */
    protected $locked = FALSE;
    
    /**
     * Flag indicating whether the field storage should be deleted when orphaned.
     *
     * By default field storages for configurable fields are removed when there
     * are no remaining fields using them. If multiple modules provide bundles
     * which need to use the same field storage then setting this to TRUE will
     * preserve the field storage regardless of what happens to the bundles. The
     * classic use case for this is node body field storage, since the Standard
     * profile and bundle (node type) creation through the UI both use same field
     * storage.
     *
     * @var bool
     */
    protected $persist_with_no_fields = FALSE;
    
    /**
     * A boolean indicating whether or not the field item uses custom storage.
     *
     * @var bool
     */
    public $custom_storage = FALSE;
    
    /**
     * The custom storage indexes for the field data storage.
     *
     * This set of indexes is merged with the "default" indexes specified by the
     * field type in the class implementing
     * \Drupal\Core\Field\FieldItemInterface::schema() method to determine the
     * actual set of indexes that get created.
     *
     * The indexes are defined using the same definition format as Schema API
     * index specifications. Only columns that are part of the field schema, as
     * defined by the field type in the class implementing
     * \Drupal\Core\Field\FieldItemInterface::schema() method, are allowed.
     *
     * Some storage backends might not support indexes, and discard that
     * information.
     *
     * @var array
     */
    protected $indexes = [];
    
    /**
     * Flag indicating whether the field is deleted.
     *
     * The delete() method marks the field as "deleted" and removes the
     * corresponding entry from the config storage, but keeps its definition in
     * the state storage while field data is purged by a separate
     * garbage-collection process.
     *
     * Deleted fields stay out of the regular entity lifecycle (notably, their
     * values are not populated in loaded entities, and are not saved back).
     *
     * @var bool
     */
    protected $deleted = FALSE;
    
    /**
     * The field schema.
     *
     * @var array
     */
    protected $schema;
    
    /**
     * An array of field property definitions.
     *
     * @var \Drupal\Core\TypedData\DataDefinitionInterface[]
     *
     * @see \Drupal\Core\TypedData\ComplexDataDefinitionInterface::getPropertyDefinitions()
     */
    protected $propertyDefinitions;
    
    /**
     * Static flag set to prevent recursion during field deletes.
     *
     * @var bool
     */
    protected static $inDeletion = FALSE;
    
    /**
     * Copy of the field before changes.
     */
    public FieldStorageConfigInterface $original;
    
    /**
     * Constructs a FieldStorageConfig object.
     *
     * In most cases, Field entities are created via
     * FieldStorageConfig::create($values)), where $values is the same parameter
     * as in this constructor.
     *
     * @param array $values
     *   An array of field properties, keyed by property name. Most array
     *   elements will be used to set the corresponding properties on the class;
     *   see the class property documentation for details. Some array elements
     *   have special meanings and a few are required. Special elements are:
     *   - name: required. As a temporary Backwards Compatibility layer right now,
     *     a 'field_name' property can be accepted in place of 'id'.
     *   - entity_type: required.
     *   - type: required.
     * @param string $entity_type
     *   (optional) The entity type on which the field should be created.
     *   Defaults to "field_storage_config".
     */
    public function __construct(array $values, $entity_type = 'field_storage_config') {
        // Check required properties.
        if (empty($values['field_name'])) {
            throw new FieldException('Attempt to create a field storage without a field name.');
        }
        if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['field_name'])) {
            throw new FieldException("Attempt to create a field storage {$values['field_name']} with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character");
        }
        if (empty($values['type'])) {
            throw new FieldException("Attempt to create a field storage {$values['field_name']} with no type.");
        }
        if (empty($values['entity_type'])) {
            throw new FieldException("Attempt to create a field storage {$values['field_name']} with no entity_type.");
        }
        parent::__construct($values, $entity_type);
    }
    
    /**
     * {@inheritdoc}
     */
    public function id() {
        return $this->getTargetEntityTypeId() . '.' . $this->getName();
    }
    
    /**
     * {@inheritdoc}
     */
    public function postCreate(EntityStorageInterface $storage) {
        parent::postCreate($storage);
        // Check that the field type is known.
        $field_type = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->type, FALSE);
        if (!$field_type) {
            throw new FieldException("Attempt to create a field storage of unknown type {$this->type}.");
        }
        $this->module = $field_type['provider'];
        // Make sure all expected runtime settings are present.
        $default_settings = \Drupal::service('plugin.manager.field.field_type')->getDefaultStorageSettings($this->getType());
        // Filter out any unknown (unsupported) settings.
        $supported_settings = array_intersect_key($this->getSettings(), $default_settings);
        $this->set('settings', $supported_settings + $default_settings);
    }
    
    /**
     * Overrides \Drupal\Core\Entity\Entity::preSave().
     *
     * @throws \Drupal\Core\Field\FieldException
     *   If the field definition is invalid.
     * @throws \Drupal\Core\Entity\EntityStorageException
     *   In case of failures at the configuration storage level.
     */
    public function preSave(EntityStorageInterface $storage) {
        // Clear the derived data about the field.
        unset($this->schema);
        // Filter out unknown settings and make sure all settings are present, so
        // that a complete field definition is passed to the various hooks and
        // written to config.
        $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
        $default_settings = $field_type_manager->getDefaultStorageSettings($this->type);
        $this->settings = array_intersect_key($this->settings, $default_settings) + $default_settings;
        if ($this->isNew()) {
            $this->preSaveNew($storage);
        }
        else {
            $this->preSaveUpdated($storage);
        }
        parent::preSave($storage);
    }
    
    /**
     * Prepares saving a new field definition.
     *
     * @param \Drupal\Core\Entity\EntityStorageInterface $storage
     *   The entity storage.
     *
     * @throws \Drupal\Core\Field\FieldException
     *   If the field definition is invalid.
     */
    protected function preSaveNew(EntityStorageInterface $storage) {
        $entity_field_manager = \Drupal::service('entity_field.manager');
        // Assign the ID.
        $this->id = $this->id();
        // Field name cannot be longer than FieldStorageConfig::NAME_MAX_LENGTH
        // characters. We use mb_strlen() because the DB layer assumes that column
        // widths are given in characters rather than bytes.
        if (mb_strlen($this->getName()) > static::NAME_MAX_LENGTH) {
            throw new FieldException('Attempt to create a field storage with an name longer than ' . static::NAME_MAX_LENGTH . ' characters: ' . $this->getName());
        }
        // Disallow reserved field names.
        $disallowed_field_names = array_keys($entity_field_manager->getBaseFieldDefinitions($this->getTargetEntityTypeId()));
        if (in_array($this->getName(), $disallowed_field_names)) {
            throw new FieldException("Attempt to create field storage {$this->getName()} which is reserved by entity type {$this->getTargetEntityTypeId()}.");
        }
        // Notify the field storage definition listener.
        \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($this);
    }
    
    /**
     * {@inheritdoc}
     */
    public function calculateDependencies() {
        parent::calculateDependencies();
        // Ensure the field is dependent on the providing module.
        $this->addDependency('module', $this->getTypeProvider());
        // Ask the field type for any additional storage dependencies.
        // @see \Drupal\Core\Field\FieldItemInterface::calculateStorageDependencies()
        $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getType(), FALSE);
        $this->addDependencies($definition['class']::calculateStorageDependencies($this));
        // Ensure the field is dependent on the provider of the entity type.
        $entity_type = \Drupal::entityTypeManager()->getDefinition($this->entity_type);
        $this->addDependency('module', $entity_type->getProvider());
        return $this;
    }
    
    /**
     * Prepares saving an updated field definition.
     *
     * @param \Drupal\Core\Entity\EntityStorageInterface $storage
     *   The entity storage.
     */
    protected function preSaveUpdated(EntityStorageInterface $storage) {
        $module_handler = \Drupal::moduleHandler();
        // Some updates are always disallowed.
        if ($this->getType() != $this->original
            ->getType()) {
            throw new FieldException(sprintf('Cannot change the field type for an existing field storage. The field storage %s has the type %s.', $this->id(), $this->original
                ->getType()));
        }
        if ($this->getTargetEntityTypeId() != $this->original
            ->getTargetEntityTypeId()) {
            throw new FieldException(sprintf('Cannot change the entity type for an existing field storage. The field storage %s has the type %s.', $this->id(), $this->original
                ->getTargetEntityTypeId()));
        }
        // See if any module forbids the update by throwing an exception. This
        // invokes hook_field_storage_config_update_forbid().
        $module_handler->invokeAll('field_storage_config_update_forbid', [
            $this,
            $this->original,
        ]);
        // Notify the field storage definition listener. A listener can reject the
        // definition update as invalid by raising an exception, which stops
        // execution before the definition is written to config.
        \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($this, $this->original);
    }
    
    /**
     * {@inheritdoc}
     */
    public function postSave(EntityStorageInterface $storage, $update = TRUE) {
        if ($update) {
            // Invalidate the render cache for all affected entities.
            $entity_type_manager = \Drupal::entityTypeManager();
            $entity_type = $this->getTargetEntityTypeId();
            if ($entity_type_manager->hasHandler($entity_type, 'view_builder')) {
                $entity_type_manager->getViewBuilder($entity_type)
                    ->resetCache();
            }
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public static function preDelete(EntityStorageInterface $storage, array $field_storages) {
        
        /** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
        $deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');
        // Set the static flag so that we don't delete field storages whilst
        // deleting fields.
        static::$inDeletion = TRUE;
        // Delete or fix any configuration that is dependent, for example, fields.
        parent::preDelete($storage, $field_storages);
        // Keep the field storage definitions in the deleted fields repository so we
        // can use them later during field_purge_batch().
        
        /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
        foreach ($field_storages as $field_storage) {
            // Only mark a field for purging if there is data. Otherwise, just remove
            // it.
            $target_entity_storage = \Drupal::entityTypeManager()->getStorage($field_storage->getTargetEntityTypeId());
            if (!$field_storage->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field_storage, TRUE)) {
                $storage_definition = clone $field_storage;
                $storage_definition->deleted = TRUE;
                $deleted_fields_repository->addFieldStorageDefinition($storage_definition);
            }
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public static function postDelete(EntityStorageInterface $storage, array $fields) {
        // Notify the storage.
        foreach ($fields as $field) {
            if (!$field->deleted) {
                \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($field);
                $field->deleted = TRUE;
            }
        }
        // Unset static flag.
        static::$inDeletion = FALSE;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getSchema() {
        if (!isset($this->schema)) {
            // Get the schema from the field item class.
            $class = $this->getFieldItemClass();
            $schema = $class::schema($this);
            // Fill in default values for optional entries.
            $schema += [
                'columns' => [],
                'unique keys' => [],
                'indexes' => [],
                'foreign keys' => [],
            ];
            // Merge custom indexes with those specified by the field type. Custom
            // indexes prevail.
            $schema['indexes'] = $this->indexes + $schema['indexes'];
            $this->schema = $schema;
        }
        return $this->schema;
    }
    
    /**
     * {@inheritdoc}
     */
    public function hasCustomStorage() {
        return $this->custom_storage;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isBaseField() {
        return FALSE;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getColumns() {
        $schema = $this->getSchema();
        return $schema['columns'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getBundles() {
        if (!$this->isDeleted()) {
            $map = \Drupal::service('entity_field.manager')->getFieldMap();
            if (isset($map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'])) {
                return $map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'];
            }
        }
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getName() {
        return $this->field_name;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isDeleted() {
        return $this->deleted;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getTypeProvider() {
        return $this->module;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getType() {
        return $this->type;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getSettings() {
        // @todo FieldTypePluginManager maintains its own static cache. However, do
        //   some CPU and memory profiling to see if it's worth statically caching
        //   $field_type_info, or the default field storage and field settings,
        //   within $this.
        $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
        $settings = $field_type_manager->getDefaultStorageSettings($this->getType());
        return $this->settings + $settings;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getSetting($setting_name) {
        // @todo See getSettings() about potentially statically caching this.
        // We assume here that one call to array_key_exists() is more efficient
        // than calling getSettings() when all we need is a single setting.
        if (array_key_exists($setting_name, $this->settings)) {
            return $this->settings[$setting_name];
        }
        $settings = $this->getSettings();
        if (array_key_exists($setting_name, $settings)) {
            return $settings[$setting_name];
        }
        else {
            return NULL;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function setSetting($setting_name, $value) {
        $this->settings[$setting_name] = $value;
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setSettings(array $settings) {
        $this->settings = $settings + $this->settings;
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isTranslatable() {
        return $this->translatable;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isRevisionable() {
        // All configurable fields are revisionable.
        return TRUE;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setTranslatable($translatable) {
        $this->translatable = $translatable;
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getProvider() {
        return 'field';
    }
    
    /**
     * {@inheritdoc}
     */
    public function getLabel() {
        return $this->label();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDescription() {
        return NULL;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCardinality() {
        
        /** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
        $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
        $definition = $field_type_manager->getDefinition($this->getType());
        $enforced_cardinality = isset($definition['cardinality']) ? (int) $definition['cardinality'] : NULL;
        // Enforced cardinality is a positive integer or -1.
        if ($enforced_cardinality !== NULL && $enforced_cardinality < 1 && $enforced_cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
            throw new FieldException("Invalid enforced cardinality '{$definition['cardinality']}'. Allowed values: a positive integer or -1.");
        }
        return $enforced_cardinality ?: $this->cardinality;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setCardinality($cardinality) {
        $this->cardinality = $cardinality;
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getOptionsProvider($property_name, FieldableEntityInterface $entity) {
        // If the field item class implements the interface, create an orphaned
        // runtime item object, so that it can be used as the options provider
        // without modifying the entity being worked on.
        if (is_subclass_of($this->getFieldItemClass(), OptionsProviderInterface::class)) {
            try {
                $items = $entity->get($this->getName());
            } catch (\InvalidArgumentException $e) {
                // When a field doesn't exist, create a new field item list using a
                // temporary base field definition. This step is necessary since there
                // may not be a field configuration for the storage when creating a new
                // field.
                // @todo Simplify in https://www.drupal.org/project/drupal/issues/3347291.
                $field_storage = BaseFieldDefinition::createFromFieldStorageDefinition($this);
                $entity_adapter = EntityAdapter::createFromEntity($entity);
                $items = \Drupal::typedDataManager()->create($field_storage, name: $field_storage->getName(), parent: $entity_adapter);
            }
            return \Drupal::service('plugin.manager.field.field_type')->createFieldItem($items, 0);
        }
        // @todo Allow setting custom options provider.
        //   https://www.drupal.org/node/2002138.
    }
    
    /**
     * {@inheritdoc}
     */
    public function isMultiple() {
        $cardinality = $this->getCardinality();
        return $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED || $cardinality > 1;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isLocked() {
        return $this->locked;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setLocked($locked) {
        $this->locked = $locked;
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getTargetEntityTypeId() {
        return $this->entity_type;
    }
    
    /**
     * Determines whether a field has any data.
     *
     * @return bool
     *   TRUE if the field has data for any entity; FALSE otherwise.
     */
    public function hasData() {
        return !$this->isNew() && \Drupal::entityTypeManager()->getStorage($this->entity_type)
            ->countFieldData($this, TRUE);
    }
    
    /**
     * Implements the magic __sleep() method.
     *
     * Using the Serialize interface and serialize() / unserialize() methods
     * breaks entity forms in PHP 5.4.
     * @todo Investigate in https://www.drupal.org/node/1977206.
     */
    public function __sleep() {
        // Only serialize necessary properties, excluding those that can be
        // recalculated.
        $properties = get_object_vars($this);
        unset($properties['schema'], $properties['propertyDefinitions'], $properties['original']);
        return array_keys($properties);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getConstraints() {
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getConstraint($constraint_name) {
        return NULL;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPropertyDefinition($name) {
        if (!isset($this->propertyDefinitions)) {
            $this->getPropertyDefinitions();
        }
        if (isset($this->propertyDefinitions[$name])) {
            return $this->propertyDefinitions[$name];
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPropertyDefinitions() {
        if (!isset($this->propertyDefinitions)) {
            $class = $this->getFieldItemClass();
            $this->propertyDefinitions = $class::propertyDefinitions($this);
        }
        return $this->propertyDefinitions;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPropertyNames() {
        return array_keys($this->getPropertyDefinitions());
    }
    
    /**
     * {@inheritdoc}
     */
    public function getMainPropertyName() {
        $class = $this->getFieldItemClass();
        return $class::mainPropertyName();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getUniqueStorageIdentifier() {
        return $this->uuid();
    }
    
    /**
     * Helper to retrieve the field item class.
     */
    protected function getFieldItemClass() {
        $type_definition = \Drupal::typedDataManager()->getDefinition('field_item:' . $this->getType());
        return $type_definition['class'];
    }
    
    /**
     * Loads a field config entity based on the entity type and field name.
     *
     * @param string $entity_type_id
     *   ID of the entity type.
     * @param string $field_name
     *   Name of the field.
     *
     * @return \Drupal\field\FieldStorageConfigInterface|null
     *   The field config entity if one exists for the provided field name,
     *   otherwise NULL.
     */
    public static function loadByName($entity_type_id, $field_name) {
        return \Drupal::entityTypeManager()->getStorage('field_storage_config')
            ->load($entity_type_id . '.' . $field_name);
    }
    
    /**
     * {@inheritdoc}
     */
    public function isDeletable() {
        // The field storage is not deleted, is configured to be removed when there
        // are no fields, the field storage has no bundles, and field storages are
        // not in the process of being deleted.
        return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0 && !static::$inDeletion;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getIndexes() {
        return $this->indexes;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setIndexes(array $indexes) {
        $this->indexes = $indexes;
        return $this;
    }

}

Members

Title Sort descending Modifiers Object type Summary Member alias Overriden Title Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ConfigEntityBase::$isUninstalling private property Whether the config is being deleted by the uninstall process.
ConfigEntityBase::$langcode protected property The language code of the entity&#039;s default language.
ConfigEntityBase::$originalId protected property The original ID of the configuration entity.
ConfigEntityBase::$status protected property The enabled/disabled status of the configuration entity. 4
ConfigEntityBase::$third_party_settings protected property
ConfigEntityBase::$trustedData protected property Trust supplied data and not use configuration schema on save.
ConfigEntityBase::$uuid protected property The UUID for this entity.
ConfigEntityBase::$_core protected property
ConfigEntityBase::addDependency protected function Overrides \Drupal\Core\Entity\DependencyTrait:addDependency().
ConfigEntityBase::createDuplicate public function Overrides EntityBase::createDuplicate 1
ConfigEntityBase::disable public function Overrides ConfigEntityInterface::disable 1
ConfigEntityBase::enable public function Overrides ConfigEntityInterface::enable
ConfigEntityBase::get public function Overrides ConfigEntityInterface::get
ConfigEntityBase::getCacheTagsToInvalidate public function Overrides EntityBase::getCacheTagsToInvalidate 1
ConfigEntityBase::getConfigDependencyName public function Overrides EntityBase::getConfigDependencyName
ConfigEntityBase::getConfigManager protected static function Gets the configuration manager.
ConfigEntityBase::getConfigTarget public function Overrides EntityBase::getConfigTarget
ConfigEntityBase::getDependencies public function Overrides ConfigEntityInterface::getDependencies
ConfigEntityBase::getOriginalId public function Overrides EntityBase::getOriginalId
ConfigEntityBase::getThirdPartyProviders public function Overrides ThirdPartySettingsInterface::getThirdPartyProviders
ConfigEntityBase::getThirdPartySetting public function Overrides ThirdPartySettingsInterface::getThirdPartySetting
ConfigEntityBase::getThirdPartySettings public function Overrides ThirdPartySettingsInterface::getThirdPartySettings
ConfigEntityBase::getTypedConfig protected function Gets the typed config manager.
ConfigEntityBase::hasTrustedData public function Overrides ConfigEntityInterface::hasTrustedData
ConfigEntityBase::invalidateTagsOnDelete protected static function Override to never invalidate the individual entities&#039; cache tags; the
config system already invalidates them.
Overrides EntityBase::invalidateTagsOnDelete
ConfigEntityBase::invalidateTagsOnSave protected function Override to never invalidate the entity&#039;s cache tag; the config system
already invalidates it.
Overrides EntityBase::invalidateTagsOnSave
ConfigEntityBase::isInstallable public function Overrides ConfigEntityInterface::isInstallable 2
ConfigEntityBase::isNew public function Overrides Entity::isNew(). Overrides EntityBase::isNew
ConfigEntityBase::isUninstalling public function Overrides ConfigEntityInterface::isUninstalling
ConfigEntityBase::onDependencyRemoval public function Overrides ConfigEntityInterface::onDependencyRemoval 8
ConfigEntityBase::save public function Overrides EntityBase::save 2
ConfigEntityBase::set public function Overrides ConfigEntityInterface::set
ConfigEntityBase::setOriginalId public function Overrides EntityBase::setOriginalId
ConfigEntityBase::setStatus public function Overrides ConfigEntityInterface::setStatus
ConfigEntityBase::setThirdPartySetting public function Overrides ThirdPartySettingsInterface::setThirdPartySetting
ConfigEntityBase::setUninstalling public function
ConfigEntityBase::sort public static function Helper callback for uasort() to sort configuration entities by weight and label. 6
ConfigEntityBase::status public function Overrides ConfigEntityInterface::status 4
ConfigEntityBase::toArray public function Overrides EntityBase::toArray 3
ConfigEntityBase::toUrl public function Overrides EntityBase::toUrl
ConfigEntityBase::trustData public function Overrides ConfigEntityInterface::trustData
ConfigEntityBase::unsetThirdPartySetting public function Overrides ThirdPartySettingsInterface::unsetThirdPartySetting
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function Aliased as: traitSleep 1
DependencySerializationTrait::__wakeup public function 2
DependencyTrait::$dependencies protected property The object&#039;s dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency. Aliased as: addDependencyTrait
EntityBase::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
EntityBase::$entityTypeId protected property The entity type.
EntityBase::$typedData protected property A typed data object wrapping this entity.
EntityBase::access public function Overrides AccessibleInterface::access 1
EntityBase::bundle public function Overrides EntityInterface::bundle 1
EntityBase::create public static function Overrides EntityInterface::create 2
EntityBase::delete public function Overrides EntityInterface::delete 1
EntityBase::enforceIsNew public function Overrides EntityInterface::enforceIsNew
EntityBase::entityTypeBundleInfo protected function Gets the entity type bundle info service.
EntityBase::entityTypeManager protected function Gets the entity type manager.
EntityBase::getCacheContexts public function Overrides CacheableDependencyTrait::getCacheContexts
EntityBase::getCacheMaxAge public function Overrides CacheableDependencyTrait::getCacheMaxAge
EntityBase::getCacheTags public function Overrides CacheableDependencyTrait::getCacheTags
EntityBase::getConfigDependencyKey public function Overrides EntityInterface::getConfigDependencyKey
EntityBase::getEntityType public function Overrides EntityInterface::getEntityType
EntityBase::getEntityTypeId public function Overrides EntityInterface::getEntityTypeId
EntityBase::getListCacheTagsToInvalidate protected function The list cache tags to invalidate for this entity.
EntityBase::getTypedData public function Overrides EntityInterface::getTypedData
EntityBase::getTypedDataClass private function Returns the typed data class name for this entity.
EntityBase::hasLinkTemplate public function Overrides EntityInterface::hasLinkTemplate
EntityBase::label public function Overrides EntityInterface::label 6
EntityBase::language public function Overrides EntityInterface::language 1
EntityBase::languageManager protected function Gets the language manager.
EntityBase::linkTemplates protected function Gets an array link templates. 1
EntityBase::load public static function Overrides EntityInterface::load
EntityBase::loadMultiple public static function Overrides EntityInterface::loadMultiple
EntityBase::postLoad public static function Overrides EntityInterface::postLoad 3
EntityBase::preCreate public static function Overrides EntityInterface::preCreate 6
EntityBase::referencedEntities public function Overrides EntityInterface::referencedEntities 1
EntityBase::toLink public function Overrides EntityInterface::toLink
EntityBase::uriRelationships public function Overrides EntityInterface::uriRelationships
EntityBase::urlRouteParameters protected function Gets an array of placeholders for this entity. 2
EntityBase::uuid public function Overrides EntityInterface::uuid 1
EntityBase::uuidGenerator protected function Gets the UUID generator.
FieldStorageConfig::$cardinality protected property The field cardinality.
FieldStorageConfig::$custom_storage public property A boolean indicating whether or not the field item uses custom storage.
FieldStorageConfig::$deleted protected property Flag indicating whether the field is deleted.
FieldStorageConfig::$entity_type protected property The name of the entity type the field can be attached to.
FieldStorageConfig::$field_name protected property The field name.
FieldStorageConfig::$id protected property The field ID.
FieldStorageConfig::$inDeletion protected static property Static flag set to prevent recursion during field deletes.
FieldStorageConfig::$indexes protected property The custom storage indexes for the field data storage.
FieldStorageConfig::$locked protected property Flag indicating whether the field is available for editing.
FieldStorageConfig::$module protected property The name of the module that provides the field type.
FieldStorageConfig::$original public property Copy of the field before changes.
FieldStorageConfig::$persist_with_no_fields protected property Flag indicating whether the field storage should be deleted when orphaned.
FieldStorageConfig::$propertyDefinitions protected property An array of field property definitions.
FieldStorageConfig::$schema protected property The field schema.
FieldStorageConfig::$settings protected property Field-type specific settings.
FieldStorageConfig::$translatable protected property Flag indicating whether the field is translatable.
FieldStorageConfig::$type protected property The field type.
FieldStorageConfig::calculateDependencies public function Calculates dependencies and stores them in the dependency property. Overrides ConfigEntityBase::calculateDependencies
FieldStorageConfig::getBundles public function Returns the list of bundles where the field storage has fields. Overrides FieldStorageConfigInterface::getBundles
FieldStorageConfig::getCardinality public function Returns the maximum number of items allowed for the field. Overrides FieldStorageDefinitionInterface::getCardinality
FieldStorageConfig::getColumns public function Returns the field columns, as defined in the field schema. Overrides FieldStorageDefinitionInterface::getColumns
FieldStorageConfig::getConstraint public function Returns a validation constraint. Overrides FieldStorageDefinitionInterface::getConstraint
FieldStorageConfig::getConstraints public function Returns an array of validation constraints. Overrides FieldStorageDefinitionInterface::getConstraints
FieldStorageConfig::getDescription public function Returns the human-readable description for the field. Overrides FieldStorageDefinitionInterface::getDescription
FieldStorageConfig::getFieldItemClass protected function Helper to retrieve the field item class.
FieldStorageConfig::getIndexes public function Returns the custom storage indexes for the field data storage. Overrides FieldStorageConfigInterface::getIndexes
FieldStorageConfig::getLabel public function Returns the human-readable label for the field. Overrides FieldStorageDefinitionInterface::getLabel
FieldStorageConfig::getMainPropertyName public function Returns the name of the main property, if any. Overrides FieldStorageDefinitionInterface::getMainPropertyName
FieldStorageConfig::getName public function Returns the machine name of the field. Overrides FieldStorageDefinitionInterface::getName
FieldStorageConfig::getOptionsProvider public function Gets an options provider for the given field item property. Overrides FieldStorageDefinitionInterface::getOptionsProvider
FieldStorageConfig::getPropertyDefinition public function Gets the definition of a contained property. Overrides FieldStorageDefinitionInterface::getPropertyDefinition
FieldStorageConfig::getPropertyDefinitions public function Gets an array of property definitions of contained properties. Overrides FieldStorageDefinitionInterface::getPropertyDefinitions
FieldStorageConfig::getPropertyNames public function Returns the names of the field&#039;s subproperties. Overrides FieldStorageDefinitionInterface::getPropertyNames
FieldStorageConfig::getProvider public function Returns the name of the provider of this field. Overrides FieldStorageDefinitionInterface::getProvider
FieldStorageConfig::getSchema public function Returns the field schema. Overrides FieldStorageDefinitionInterface::getSchema
FieldStorageConfig::getSetting public function Returns the value of a given storage setting. Overrides FieldStorageDefinitionInterface::getSetting
FieldStorageConfig::getSettings public function Returns the storage settings. Overrides FieldStorageDefinitionInterface::getSettings
FieldStorageConfig::getTargetEntityTypeId public function Returns the ID of the entity type the field is attached to. Overrides FieldStorageDefinitionInterface::getTargetEntityTypeId
FieldStorageConfig::getType public function Returns the field type. Overrides FieldStorageConfigInterface::getType
FieldStorageConfig::getTypeProvider public function Returns the name of the module providing the field type. Overrides FieldStorageConfigInterface::getTypeProvider
FieldStorageConfig::getUniqueStorageIdentifier public function Returns a unique identifier for the field storage. Overrides FieldStorageDefinitionInterface::getUniqueStorageIdentifier
FieldStorageConfig::hasCustomStorage public function Returns the storage behavior for this field. Overrides FieldStorageDefinitionInterface::hasCustomStorage
FieldStorageConfig::hasData public function Determines whether a field has any data.
FieldStorageConfig::id public function Gets the identifier. Overrides EntityBase::id
FieldStorageConfig::isBaseField public function Determines whether the field is a base field. Overrides FieldStorageDefinitionInterface::isBaseField
FieldStorageConfig::isDeletable public function Checks if the field storage can be deleted. Overrides FieldStorageConfigInterface::isDeletable
FieldStorageConfig::isDeleted public function Returns whether the field is deleted or not. Overrides FieldStorageDefinitionInterface::isDeleted
FieldStorageConfig::isLocked public function Returns whether the field storage is locked or not. Overrides FieldStorageConfigInterface::isLocked
FieldStorageConfig::isMultiple public function Returns whether the field can contain multiple items. Overrides FieldStorageDefinitionInterface::isMultiple
FieldStorageConfig::isRevisionable public function Returns whether the field storage is revisionable. Overrides FieldStorageDefinitionInterface::isRevisionable
FieldStorageConfig::isTranslatable public function Returns whether the field supports translation. Overrides FieldStorageDefinitionInterface::isTranslatable
FieldStorageConfig::loadByName public static function Loads a field config entity based on the entity type and field name.
FieldStorageConfig::NAME_MAX_LENGTH constant The maximum length of the field name, in characters.
FieldStorageConfig::postCreate public function Acts on a created entity before hooks are invoked. Overrides EntityBase::postCreate
FieldStorageConfig::postDelete public static function Acts on deleted entities before the delete hook is invoked. Overrides EntityBase::postDelete
FieldStorageConfig::postSave public function Acts on a saved entity before the insert or update hook is invoked. Overrides EntityBase::postSave
FieldStorageConfig::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. Overrides ConfigEntityBase::preDelete
FieldStorageConfig::preSave public function Overrides \Drupal\Core\Entity\Entity::preSave(). Overrides ConfigEntityBase::preSave
FieldStorageConfig::preSaveNew protected function Prepares saving a new field definition.
FieldStorageConfig::preSaveUpdated protected function Prepares saving an updated field definition.
FieldStorageConfig::setCardinality public function Sets the maximum number of items allowed for the field. Overrides FieldStorageConfigInterface::setCardinality
FieldStorageConfig::setIndexes public function Sets the custom storage indexes for the field data storage.. Overrides FieldStorageConfigInterface::setIndexes
FieldStorageConfig::setLocked public function Sets the locked flag. Overrides FieldStorageConfigInterface::setLocked
FieldStorageConfig::setSetting public function Sets the value for a field setting by name. Overrides FieldStorageConfigInterface::setSetting
FieldStorageConfig::setSettings public function Sets field storage settings. Overrides FieldStorageConfigInterface::setSettings
FieldStorageConfig::setTranslatable public function Sets whether the field is translatable. Overrides FieldStorageConfigInterface::setTranslatable
FieldStorageConfig::__construct public function Constructs a FieldStorageConfig object. Overrides ConfigEntityBase::__construct
FieldStorageConfig::__sleep public function Implements the magic __sleep() method. Overrides ConfigEntityBase::__sleep
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED constant Value indicating a field accepts an unlimited number of values.
PluginDependencyTrait::calculatePluginDependencies protected function Calculates and adds dependencies of a specific plugin instance. 1
PluginDependencyTrait::getPluginDependencies protected function Calculates and returns dependencies of a specific plugin instance.
PluginDependencyTrait::moduleHandler protected function Wraps the module handler. 1
PluginDependencyTrait::themeHandler protected function Wraps the theme handler. 1
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
SynchronizableEntityTrait::$isSyncing protected property Is entity being created updated or deleted through synchronization process.
SynchronizableEntityTrait::isSyncing public function
SynchronizableEntityTrait::setSyncing public function

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