예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     if ($row->hasDestinationProperty('langcode')) {
         $this->config = $this->language_manager->getLanguageConfigOverride($row->getDestinationProperty('langcode'), $this->config->getName());
     }
     foreach ($row->getRawDestination() as $key => $value) {
         if (isset($value) || !empty($this->configuration['store null'])) {
             $this->config->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $key), $value);
         }
     }
     $this->config->save();
     return [$this->config->getName()];
 }
예제 #2
0
 /**
  * Updates an entity with the new values from row.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity to update.
  * @param \Drupal\migrate\Row $row
  *   The row object to update from.
  *
  * @return \Drupal\Core\Entity\EntityInterface|null
  *   An updated entity, or NULL if it's the same as the one passed in.
  */
 protected function updateEntity(EntityInterface $entity, Row $row)
 {
     // By default, an update will be preserved.
     $rollback_action = MigrateIdMapInterface::ROLLBACK_PRESERVE;
     // Make sure we have the right translation.
     if ($this->isTranslationDestination()) {
         $property = $this->storage->getEntityType()->getKey('langcode');
         if ($row->hasDestinationProperty($property)) {
             $language = $row->getDestinationProperty($property);
             if (!$entity->hasTranslation($language)) {
                 $entity->addTranslation($language);
                 // We're adding a translation, so delete it on rollback.
                 $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE;
             }
             $entity = $entity->getTranslation($language);
         }
     }
     // If the migration has specified a list of properties to be overwritten,
     // clone the row with an empty set of destination values, and re-add only
     // the specified properties.
     if (isset($this->configuration['overwrite_properties'])) {
         $clone = $row->cloneWithoutDestination();
         foreach ($this->configuration['overwrite_properties'] as $property) {
             $clone->setDestinationProperty($property, $row->getDestinationProperty($property));
         }
         $row = $clone;
     }
     foreach ($row->getDestination() as $field_name => $values) {
         $field = $entity->{$field_name};
         if ($field instanceof TypedDataInterface) {
             $field->setValue($values);
         }
     }
     $this->setRollbackAction($row->getIdMap(), $rollback_action);
     // We might have a different (translated) entity, so return it.
     return $entity;
 }
예제 #3
0
파일: RowTest.php 프로젝트: aWEBoLabs/taxi
 /**
  * Tests setting/getting multiple destination IDs.
  */
 public function testMultipleDestination()
 {
     $row = new Row($this->testValues, $this->testSourceIds);
     // Set some deep nested values.
     $row->setDestinationProperty('image/alt', 'alt text');
     $row->setDestinationProperty('image/fid', 3);
     $this->assertTrue($row->hasDestinationProperty('image'));
     $this->assertFalse($row->hasDestinationProperty('alt'));
     $this->assertFalse($row->hasDestinationProperty('fid'));
     $destination = $row->getDestination();
     $this->assertEquals('alt text', $destination['image']['alt']);
     $this->assertEquals(3, $destination['image']['fid']);
     $this->assertEquals('alt text', $row->getDestinationProperty('image/alt'));
     $this->assertEquals(3, $row->getDestinationProperty('image/fid'));
 }