FieldStorageConfig::__construct

public FieldStorageConfig::__construct(array $values, $entity_type = 'field_storage_config')

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.

Overrides ConfigEntityBase::__construct

See also

entity_create()

File

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

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);
}
doc_Drupal
2016-10-29 09:12:25
Comments
Leave a Comment

Please login to continue.