function FieldStorageConfig::__construct

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

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.

Parameters

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.

string $entity_type: (optional) The entity type on which the field should be created. Defaults to "field_storage_config".

Overrides ConfigEntityBase::__construct

File

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

Class

FieldStorageConfig
Defines the Field storage configuration entity.

Namespace

Drupal\field\Entity

Code

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

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