public function Field::getSchema

Returns the field 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 FieldInterface::getSchema

1 call to Field::getSchema()
Field::offsetGet in drupal/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php

File

drupal/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php, line 497
Contains \Drupal\field\Plugin\Core\Entity\Field.

Class

Field
Defines the Field entity.

Namespace

Drupal\field\Plugin\Core\Entity

Code

public function getSchema() {
  if (!isset($this->schema)) {
    $module_handler = \Drupal::moduleHandler();

    // Collect the schema from the field type.
    // @todo Use $module_handler->loadInclude() once
    // http://drupal.org/node/1941000 is fixed.
    module_load_install($this->module);

    // Invoke hook_field_schema() for the field.
    $schema = (array) $module_handler
      ->invoke($this->module, 'field_schema', array(
      $this,
    ));
    $schema += array(
      'columns' => array(),
      'indexes' => array(),
      'foreign keys' => array(),
    );

    // Check that the schema does not include forbidden column names.
    if (array_intersect(array_keys($schema['columns']), static::getReservedColumns())) {
      throw new FieldException('Illegal field type columns.');
    }

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