summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-01-26 12:37:29 (GMT)
committerAlex Pott2015-01-26 12:37:29 (GMT)
commitfcb679d878a8302fe227b9ff6165563b6696f88e (patch)
treed0a6c8981a05a59841e1ae97b5c78c424566a314
parent20a76f00f9dd81456573adc2511ff5eda8f9d1b4 (diff)
Issue #2405023 by benjy: Cannot create base_field_override entity, ID already exists
-rw-r--r--core/modules/migrate/src/Plugin/migrate/destination/Entity.php14
-rw-r--r--core/modules/migrate/src/Plugin/migrate/destination/EntityBaseFieldOverride.php29
-rw-r--r--core/modules/migrate_drupal/src/Tests/d6/MigrateNodeBundleSettingsTest.php3
3 files changed, 45 insertions, 1 deletions
diff --git a/core/modules/migrate/src/Plugin/migrate/destination/Entity.php b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php
index 8d69f80..60a2a0c 100644
--- a/core/modules/migrate/src/Plugin/migrate/destination/Entity.php
+++ b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php
@@ -106,7 +106,7 @@ abstract class Entity extends DestinationBase implements ContainerFactoryPluginI
* The entity we're importing into.
*/
protected function getEntity(Row $row, array $old_destination_id_values) {
- $entity_id = $old_destination_id_values ? reset($old_destination_id_values) : $row->getDestinationProperty($this->getKey('id'));
+ $entity_id = $old_destination_id_values ? reset($old_destination_id_values) : $this->getEntityId($row);
if (!empty($entity_id) && ($entity = $this->storage->load($entity_id))) {
$this->updateEntity($entity, $row);
}
@@ -126,6 +126,18 @@ abstract class Entity extends DestinationBase implements ContainerFactoryPluginI
}
/**
+ * Get the entity id of the row.
+ *
+ * @param \Drupal\migrate\Row $row
+ * The row of data.
+ * @return string
+ * The entity id for the row we're importing.
+ */
+ protected function getEntityId(Row $row) {
+ return $row->getDestinationProperty($this->getKey('id'));
+ }
+
+ /**
* Returns a specific entity key.
*
* @param string $key
diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityBaseFieldOverride.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityBaseFieldOverride.php
new file mode 100644
index 0000000..449073c
--- /dev/null
+++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityBaseFieldOverride.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\migrate\Plugin\migrate\destination\EntityBaseFieldOverride
+ */
+
+namespace Drupal\migrate\Plugin\migrate\destination;
+
+use Drupal\migrate\Row;
+
+/**
+ * @MigrateDestination(
+ * id = "entity:base_field_override"
+ * )
+ */
+class EntityBaseFieldOverride extends EntityConfigBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getEntityId(Row $row) {
+ $entity_type = $row->getDestinationProperty('entity_type');
+ $bundle = $row->getDestinationProperty('bundle');
+ $field_name = $row->getDestinationProperty('field_name');
+ return "$entity_type.$bundle.$field_name";
+ }
+
+}
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeBundleSettingsTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeBundleSettingsTest.php
index 38ceca1..503780c 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeBundleSettingsTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeBundleSettingsTest.php
@@ -44,6 +44,9 @@ class MigrateNodeBundleSettingsTest extends MigrateDrupalTestBase {
entity_create('node_type', array('type' => 'event'))->save();
entity_create('node_type', array('type' => 'book'))->save();
+ // Create a config entity that already exists.
+ entity_create('base_field_override', array('field_name' => 'promote', 'entity_type' => 'node', 'bundle' => 'page',))->save();
+
$id_mappings = array(
'd6_node_type' => array(
array(array('test_page'), array('test_page')),