You are here

public function FieldStorageConfig::__construct in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::__construct()

Constructs a FieldStorageConfig object.

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.

In most cases, Field entities are created via entity_create('field_storage_config', $values)), where $values is the same parameter as in this constructor.

Overrides ConfigEntityBase::__construct

See also

entity_create()

File

core/modules/field/src/Entity/FieldStorageConfig.php, line 246
Contains \Drupal\field\Entity\FieldStorageConfig.

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