Issue #2405023 by benjy: Cannot create base_field_override entity, ID already exists

8.0.x
Alex Pott 2015-01-26 12:37:29 +00:00
parent 20a76f00f9
commit fcb679d878
3 changed files with 45 additions and 1 deletions

View File

@ -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);
}
@ -125,6 +125,18 @@ abstract class Entity extends DestinationBase implements ContainerFactoryPluginI
return $entity;
}
/**
* 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.
*

View File

@ -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";
}
}

View File

@ -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')),