public function BaseFieldDefinition::getSchema

public BaseFieldDefinition::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 hook_field_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.
  • 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

File

core/lib/Drupal/Core/Field/BaseFieldDefinition.php, line 629

Class

BaseFieldDefinition
A class for defining entity fields.

Namespace

Drupal\Core\Field

Code

public function getSchema() {
  if (!isset($this->schema)) {
    // Get the schema from the field item class.
    $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getType());
    $class = $definition['class'];
    $schema = $class::schema($this);
    // Fill in default values.
    $schema += array(
      'columns' => array(),
      'unique keys' => array(),
      'indexes' => array(),
      'foreign keys' => array(),
    );

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!BaseFieldDefinition.php/function/BaseFieldDefinition::getSchema/8.1.x