Commit 684f0cb4 authored by webchick's avatar webchick

Issue #2224833 by tim.plunkett: Remove redundant ID manipulation in ConfigEntityStorage::save().

parent 9d2e9ff3
......@@ -131,7 +131,7 @@ public function loadMultiple(array $ids = NULL) {
// Remove any invalid ids from the array.
$passed_ids = array_intersect_key($passed_ids, $entities);
foreach ($entities as $entity) {
$passed_ids[$entity->{$this->idKey}] = $entity;
$passed_ids[$entity->id()] = $entity;
}
$entities = $passed_ids;
}
......@@ -310,11 +310,6 @@ public function save(EntityInterface $entity) {
$entity->original = $this->loadUnchanged($id);
}
// Build an ID if none is set.
if (!isset($entity->{$this->idKey})) {
$entity->{$this->idKey} = $entity->id();
}
$entity->preSave($this);
$this->invokeHook('presave', $entity);
......
......@@ -86,7 +86,7 @@ function entity_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new)
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
$display = entity_load('entity_view_display', $id);
$new_id = $entity_type_id . '.' . $bundle_new . '.' . $display->mode;
$display->id = $new_id;
$display->set('id', $new_id);
$display->bundle = $bundle_new;
$display->save();
}
......@@ -100,7 +100,7 @@ function entity_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new)
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
$form_display = entity_load('entity_form_display', $id);
$new_id = $entity_type_id . '.' . $bundle_new . '.' . $form_display->mode;
$form_display->id = $new_id;
$form_display->set('id', $new_id);
$form_display->bundle = $bundle_new;
$form_display->save();
}
......
......@@ -198,7 +198,6 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
*/
public function toArray() {
$names = array(
'id',
'uuid',
'targetEntityType',
'bundle',
......@@ -208,7 +207,9 @@ public function toArray() {
'status',
'dependencies'
);
$properties = array();
$properties = array(
'id' => $this->id(),
);
foreach ($names as $name) {
$properties[$name] = $this->get($name);
}
......
......@@ -200,7 +200,7 @@ function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
foreach ($instances as $instance) {
if ($instance->entity_type == $entity_type && $instance->bundle == $bundle_old) {
$id_new = $instance->entity_type . '.' . $bundle_new . '.' . $instance->field_name;
$instance->id = $id_new;
$instance->set('id', $id_new);
$instance->bundle = $bundle_new;
$instance->allowBundleRename();
$instance->save();
......
......@@ -239,7 +239,6 @@ public function id() {
*/
public function toArray() {
$names = array(
'id',
'uuid',
'status',
'langcode',
......@@ -254,7 +253,9 @@ public function toArray() {
'indexes',
'dependencies',
);
$properties = array();
$properties = array(
'id' => $this->id(),
);
foreach ($names as $name) {
$properties[$name] = $this->get($name);
}
......
......@@ -283,7 +283,7 @@ public function __construct(array $values, $entity_type = 'field_instance_config
* {@inheritdoc}
*/
public function id() {
return $this->entity_type . '.' . $this->bundle . '.' . $this->field->name;
return $this->entity_type . '.' . $this->bundle . '.' . $this->field_name;
}
/**
......@@ -291,7 +291,6 @@ public function id() {
*/
public function toArray() {
$names = array(
'id',
'uuid',
'status',
'langcode',
......@@ -307,7 +306,9 @@ public function toArray() {
'settings',
'dependencies',
);
$properties = array();
$properties = array(
'id' => $this->id(),
);
foreach ($names as $name) {
$properties[$name] = $this->get($name);
}
......
......@@ -135,7 +135,7 @@ public function loadByProperties(array $conditions = array()) {
// When returning deleted fields, key the results by UUID since they can
// include several fields with the same ID.
$key = $include_deleted ? $field->uuid : $field->id;
$key = $include_deleted ? $field->uuid() : $field->id();
$matching_fields[$key] = $field;
}
......
......@@ -115,7 +115,8 @@ public function testDefaultImages() {
->save();
// Confirm the defaults are present on the article field settings form.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id/field");
$instance_id = $instance->id();
$this->drupalGet("admin/structure/types/manage/article/fields/$instance_id/field");
$this->assertFieldByXpath(
'//input[@name="field[settings][default_image][fid][fids]"]',
$default_images['field']->id(),
......@@ -125,7 +126,7 @@ public function testDefaultImages() {
)
);
// Confirm the defaults are present on the article field edit form.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id");
$this->drupalGet("admin/structure/types/manage/article/fields/$instance_id");
$this->assertFieldByXpath(
'//input[@name="instance[settings][default_image][fid][fids]"]',
$default_images['instance']->id(),
......@@ -136,7 +137,7 @@ public function testDefaultImages() {
);
// Confirm the defaults are present on the page field settings form.
$this->drupalGet("admin/structure/types/manage/page/fields/$instance->id/field");
$this->drupalGet("admin/structure/types/manage/page/fields/$instance_id/field");
$this->assertFieldByXpath(
'//input[@name="field[settings][default_image][fid][fids]"]',
$default_images['field']->id(),
......@@ -146,7 +147,8 @@ public function testDefaultImages() {
)
);
// Confirm the defaults are present on the page field edit form.
$this->drupalGet("admin/structure/types/manage/page/fields/$instance2->id");
$instance2_id = $instance2->id();
$this->drupalGet("admin/structure/types/manage/page/fields/$instance2_id");
$this->assertFieldByXpath(
'//input[@name="instance[settings][default_image][fid][fids]"]',
$default_images['instance2']->id(),
......@@ -185,7 +187,7 @@ public function testDefaultImages() {
$field->save();
// Confirm that the new default is used on the article field settings form.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id/field");
$this->drupalGet("admin/structure/types/manage/article/fields/$instance_id/field");
$this->assertFieldByXpath(
'//input[@name="field[settings][default_image][fid][fids]"]',
$default_images['field_new']->id(),
......@@ -221,7 +223,7 @@ public function testDefaultImages() {
// Confirm the new field instance default is used on the article field
// admin form.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id");
$this->drupalGet("admin/structure/types/manage/article/fields/$instance_id");
$this->assertFieldByXpath(
'//input[@name="instance[settings][default_image][fid][fids]"]',
$default_images['instance_new']->id(),
......@@ -259,7 +261,7 @@ public function testDefaultImages() {
$instance->save();
// Confirm the article field instance default has been removed.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id");
$this->drupalGet("admin/structure/types/manage/article/fields/$instance_id");
$this->assertFieldByXpath(
'//input[@name="instance[settings][default_image][fid][fids]"]',
'',
......
......@@ -138,14 +138,15 @@ public function id() {
*/
public function toArray() {
$names = array(
'id',
'uuid',
'targetEntityType',
'bundle',
'types',
'fieldMappings',
);
$properties = array();
$properties = array(
'id' => $this->id(),
);
foreach ($names as $name) {
$properties[$name] = $this->get($name);
}
......
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