Overrides DatabaseStorageController::create().
array $values: An array of values to set, keyed by field name. The value has to be the plain value of an entity field, i.e. an array of field items. If no numerically indexed array is given, the value will be set for the first field item. For example, to set the first item of a 'name' property one can pass:
$values = array(
'name' => array(
0 => array(
'value' => 'the name',
),
),
);
or
$values = array(
'name' => array(
'value' => 'the name',
),
);
If the 'name' field is a defined as 'string_item' which supports setting by string value, it's also possible to just pass the name string:
$values = array(
'name' => 'the name',
);
Drupal\Core\Entity\EntityInterface A new entity object.
Overrides DatabaseStorageController::create
public function create(array $values) {
$entity = new $this->entityClass(array(), $this->entityType);
// Make sure to set the bundle first.
if ($this->bundleKey) {
$entity->{$this->bundleKey} = $values[$this->bundleKey];
unset($values[$this->bundleKey]);
}
// Set all other given values.
foreach ($values as $name => $value) {
$entity->{$name} = $value;
}
// Assign a new UUID if there is none yet.
if ($this->uuidKey && !isset($entity->{$this->uuidKey})) {
$uuid = new Uuid();
$entity->{$this->uuidKey}->value = $uuid
->generate();
}
return $entity;
}