function FieldStorageConfig::getSchema

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

Returns the field schema.

Note that this method returns an empty array for computed fields which have no schema.

Return value

array[] The field schema, as an array of key/value pairs in the format returned by \Drupal\Core\Field\FieldItemInterface::schema():

  • columns: An array of Schema API column specifications, keyed by column name. This specifies what comprises a single value for a given field. No assumptions should be made on how storage backends internally use the original column name to structure their storage.
  • indexes: An array of Schema API index definitions. Some storage backends might not support indexes.
  • unique keys: An array of Schema API unique key definitions. Some storage backends might not support unique keys.
  • foreign keys: An array of Schema API foreign key definitions. Note, however, that depending on the storage backend specified for the field, the field data is not necessarily stored in SQL.

Overrides FieldStorageDefinitionInterface::getSchema

1 call to FieldStorageConfig::getSchema()
FieldStorageConfig::getColumns in core/modules/field/src/Entity/FieldStorageConfig.php
Returns the field columns, as defined in the field schema.

File

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

Class

FieldStorageConfig
Defines the Field storage configuration entity.

Namespace

Drupal\field\Entity

Code

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;
}

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