Constructs a Field object.
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:
In most cases, Field entities are created via entity_create('field_entity', $values)), where $values is the same parameter as in this constructor.
Overrides ConfigEntityBase::__construct
public function __construct(array $values, $entity_type = 'field_entity') {
// Check required properties.
if (empty($values['type'])) {
throw new FieldException('Attempt to create a field with no type.');
}
// Temporary BC layer: accept both 'id' and 'field_name'.
// @todo $field_name and the handling for it will be removed in
// http://drupal.org/node/1953408.
if (empty($values['field_name']) && empty($values['id'])) {
throw new FieldException('Attempt to create an unnamed field.');
}
if (empty($values['id'])) {
$values['id'] = $values['field_name'];
unset($values['field_name']);
}
if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['id'])) {
throw new FieldException('Attempt to create a field with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character');
}
parent::__construct($values, $entity_type);
}