- Issue created by @joelpittet
- π¨π¦Canada joelpittet Vancouver
We created a custom destination plugin to lookup the value in the getEntity() method, the only suspicious part is I hardcoded english because we aren't migrating the langcode:
<?php declare(strict_types=1); namespace Drupal\custom_migration\Plugin\migrate\destination; use Drupal\migrate\Attribute\MigrateDestination; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; use Drupal\migrate\Row; /** * The 'registration_settings' destination plugin. */ #[MigrateDestination( id: 'registration_settings' )] final class RegistrationSettings extends EntityContentBase { /** * The entity type plugin id for RegistrationSettings entity. */ protected static function getEntityTypeId($plugin_id): string { return 'registration_settings'; } /** * {@inheritdoc} */ protected function getEntity(Row $row, array $old_destination_id_values) { // Extract the keys to determine if the entity already exists. $entity_type_id = $row->getSourceProperty('entity_type'); $entity_id = $row->getSourceProperty('entity_id'); // Hardcode en if not available. $langcode = $row->getSourceProperty('langcode') ?? 'en'; // Load the existing entity if it exists. $existing_entities = $this->storage->loadByProperties([ 'entity_type_id' => $entity_type_id, 'entity_id' => $entity_id, 'langcode' => $langcode, ]); // Get the first match, if any. $entity = reset($existing_entities); if ($entity) { // Allow updateEntity() to change the entity. $entity = $this->updateEntity($entity, $row) ?: $entity; } else { // Attempt to ensure we always have a bundle. if ($bundle = $this->getBundle($row)) { $row->setDestinationProperty($this->getKey('bundle'), $bundle); } // Stubs might need some required fields filled in. if ($row->isStub()) { $this->processStubRow($row); } $entity = $this->storage->create($row->getDestination()); $entity->enforceIsNew(); } return $entity; } }
- Status changed to Needs review
7 days ago 11:27pm 26 March 2025 - πΊπΈUnited States john.oltman
@joelpittet thanks for posting this, your destination plugin looks good, glad you found a solution. However, I was not able to reproduce the error in my test environment - do you have multiple languages installed on your site by chance.
- π¨π¦Canada joelpittet Vancouver
Yes and no:), we have language enabled because search_api or the solr extension requires it but we are doing that one to one, und to en.
Do you think that is the ticket?