Commit dca2d601 authored by webchick's avatar webchick
Browse files

Issue #1857442 by longwave, dawehner: Make $values optional on entity_create.

parent f6dd96ca
......@@ -377,16 +377,16 @@ function entity_delete_multiple($entity_type, array $ids) {
/**
* Constructs a new entity object, without permanently saving it.
*
* @param $entity_type
* @param string $entity_type
* The type of the entity.
* @param $values
* An array of values to set, keyed by property name. If the entity type has
* bundles the bundle key has to be specified.
* @param array $values
* (optional) An array of values to set, keyed by property name. If the
* entity type has bundles, the bundle key has to be specified.
*
* @return \Drupal\Core\Entity\EntityInterface
* A new entity object.
*/
function entity_create($entity_type, array $values) {
function entity_create($entity_type, array $values = array()) {
return \Drupal::entityManager()
->getStorageController($entity_type)
->create($values);
......
......@@ -248,7 +248,7 @@ protected function buildQuery($ids, $revision_id = FALSE) {
/**
* Implements Drupal\Core\Entity\EntityStorageControllerInterface::create().
*/
public function create(array $values) {
public function create(array $values = array()) {
$class = $this->entityType->getClass();
$class::preCreate($this, $values);
......
......@@ -235,7 +235,7 @@ protected function buildQuery($ids, $revision_id = FALSE) {
/**
* {@inheritdoc}
*/
public function create(array $values) {
public function create(array $values = array()) {
$entity_class = $this->entityType->getClass();
$entity_class::preCreate($this, $values);
......
......@@ -111,14 +111,14 @@ public function loadByProperties(array $values = array());
/**
* Constructs a new entity object, without permanently saving it.
*
* @param $values
* An array of values to set, keyed by property name. If the entity type has
* bundles the bundle key has to be specified.
* @param array $values
* (optional) An array of values to set, keyed by property name. If the
* entity type has bundles, the bundle key has to be specified.
*
* @return \Drupal\Core\Entity\EntityInterface
* A new entity object.
*/
public function create(array $values);
public function create(array $values = array());
/**
* Deletes permanently saved entities.
......
......@@ -55,7 +55,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
/**
* {@inheritdoc}
*/
public function create(array $values) {
public function create(array $values = array()) {
$entity_class = $this->entityType->getClass();
$entity_class::preCreate($this, $values);
......
......@@ -61,7 +61,7 @@ protected function defineOptions() {
*/
public function render(ResultRow $values) {
if (!empty($this->options['link_to_user'])) {
$account = entity_create('user', array());
$account = entity_create('user');
$account->name = $this->getValue($values);
$account->uid = $values->{$this->uid};
$username = array(
......
......@@ -61,7 +61,7 @@ public function buildOptionsForm(&$form, &$form_state) {
*/
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_user'])) {
$account = entity_create('user', array());
$account = entity_create('user');
$account->uid = $this->getValue($values, 'uid');
$account->name = $this->getValue($values);
$account->homepage = $this->getValue($values, 'homepage');
......
......@@ -38,7 +38,7 @@ public static function getInfo() {
function testCRUD() {
$default_langcode = language_default()->id;
// Verify default properties on a newly created empty entity.
$empty = entity_create('config_test', array());
$empty = entity_create('config_test');
$this->assertIdentical($empty->id, NULL);
$this->assertTrue($empty->uuid);
$this->assertIdentical($empty->label, NULL);
......
......@@ -58,7 +58,7 @@ public function setUp() {
*/
public function testDateTimeItem() {
// Verify entity creation.
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity->field_datetime = $value;
$entity->name->value = $this->randomName();
......@@ -88,7 +88,7 @@ public function testDateTimeItem() {
*/
public function testSetValue() {
// Test DateTimeItem::setValue() using string.
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity->get('field_datetime')->set(0, $value);
$entity->save();
......@@ -98,7 +98,7 @@ public function testSetValue() {
$this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with string value.');
// Test DateTimeItem::setValue() using property array.
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity->set('field_datetime', $value);
$entity->save();
......@@ -113,7 +113,7 @@ public function testSetValue() {
*/
public function testSetValueProperty() {
// Test Date::setValue().
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity->set('field_datetime', $value);
......
......@@ -74,7 +74,7 @@ public function testText() {
);
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$field_name}->value = 'Hello, world!';
$this->entity->{$field_name}->format = 'full_html';
$this->entity->save();
......@@ -126,7 +126,7 @@ public function testTextWysiwyg() {
);
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$field_name}->value = 'Hello, world!';
$this->entity->{$field_name}->format = 'filtered_html';
$this->entity->save();
......@@ -163,7 +163,7 @@ public function testNumber() {
);
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$field_name}->value = 42;
$this->entity->save();
......
......@@ -95,7 +95,7 @@ public function testSimpleEntityType() {
);
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$field_1_name}->value = 'Test';
$this->entity->{$field_2_name}->value = 42;
$this->entity->save();
......@@ -161,7 +161,7 @@ public function testEditorWithCustomMetadata() {
$full_html_format->save();
// Create an entity with values for this rich text field.
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$field_name}->value = 'Test';
$this->entity->{$field_name}->format = 'full_html';
$this->entity->save();
......
......@@ -127,7 +127,7 @@ public function testEditorSelection() {
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$this->field_name}->value = 'Hello, world!';
$this->entity->{$this->field_name}->format = 'filtered_html';
$this->entity->save();
......@@ -156,7 +156,7 @@ public function testMetadata() {
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
// Create an entity with values for the field.
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$this->field_name}->value = 'Test';
$this->entity->{$this->field_name}->format = 'full_html';
$this->entity->save();
......@@ -183,7 +183,7 @@ public function testMetadata() {
*/
public function testGetUntransformedTextCommand() {
// Create an entity with values for the field.
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$this->field_name}->value = 'Test';
$this->entity->{$this->field_name}->format = 'full_html';
$this->entity->save();
......
......@@ -59,7 +59,7 @@ public function setUp() {
* Tests the configurable text editor manager.
*/
public function testEditorEntityHooks() {
$image = entity_create('file', array());
$image = entity_create('file');
$image->setFileUri('core/misc/druplicon.png');
$image->setFilename(drupal_basename($image->getFileUri()));
$image->save();
......
......@@ -59,7 +59,7 @@ public function setUp() {
*/
public function testEmailItem() {
// Verify entity creation.
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$value = 'test@example.com';
$entity->field_email = $value;
$entity->name->value = $this->randomName();
......
......@@ -81,7 +81,7 @@ public function testContentEntityReferenceItem() {
$tid = $this->term->id();
// Just being able to create the entity like this verifies a lot of code.
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$entity->field_test_taxonomy_term->target_id = $tid;
$entity->name->value = $this->randomName();
$entity->save();
......@@ -128,7 +128,7 @@ public function testConfigEntityReferenceItem() {
$referenced_entity_id = $this->vocabulary->id();
// Just being able to create the entity like this verifies a lot of code.
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$entity->field_test_taxonomy_vocabulary->target_id = $referenced_entity_id;
$entity->name->value = $this->randomName();
$entity->save();
......
......@@ -348,7 +348,7 @@ function testDeleteField() {
$this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new instance for a previously used field name is created.');
// Save an entity with data for the field
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$values[0]['value'] = mt_rand(1, 127);
$entity->{$field->getName()}->value = $values[0]['value'];
$entity = $this->entitySaveReload($entity);
......@@ -402,7 +402,7 @@ function testUpdateField() {
$instance->save();
do {
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
// Fill in the entity with more values than $cardinality.
for ($i = 0; $i < 20; $i++) {
// We can not use $i here because 0 values are filtered out.
......
......@@ -110,7 +110,7 @@ function setUp() {
// Create an entity with values.
$this->values = $this->_generateTestFieldValues($this->cardinality);
$this->entity = entity_create('entity_test', array());
$this->entity = entity_create('entity_test');
$this->entity->{$this->field_name}->setValue($this->values);
$this->entity->save();
}
......
......@@ -48,7 +48,7 @@ function testFieldAttachView() {
$this->createFieldWithInstance('_2');
$entity_type = 'entity_test';
$entity_init = entity_create($entity_type, array());
$entity_init = entity_create($entity_type);
// Populate values to be displayed.
$values = $this->_generateTestFieldValues($this->field->getCardinality());
......
......@@ -58,7 +58,7 @@ function testFieldAttachSaveLoad() {
// TODO : test empty values filtering and "compression" (store consecutive deltas).
// Preparation: create three revisions and store them in $revision array.
$values = array();
$entity = entity_create($entity_type, array());
$entity = entity_create($entity_type);
for ($revision_id = 0; $revision_id < 3; $revision_id++) {
// Note: we try to insert one extra value.
$current_values = $this->_generateTestFieldValues($cardinality + 1);
......
......@@ -60,7 +60,7 @@ public function setUp() {
*/
public function testShapeItem() {
// Verify entity creation.
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test');
$shape = 'cube';
$color = 'blue';
$entity->{$this->field_name}->shape = $shape;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment