public function EntityTestStorageController::create

Overrides DatabaseStorageController::create().

Parameters

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' field 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 its value by a string, it's also possible to just pass the name string:

$values = array(
  'name' => 'the name',
);

Return value

\Drupal\Core\Entity\EntityInterface A new entity object.

Overrides DatabaseStorageControllerNG::create

File

drupal/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php, line 23
Definition of Drupal\entity_test\EntityTestStorageController.

Class

EntityTestStorageController
Defines the controller class for the test entity.

Namespace

Drupal\entity_test

Code

public function create(array $values) {
  if (empty($values['type'])) {
    $values['type'] = $this->entityType;
  }
  return parent::create($values);
}