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