getDestinationProperty example

$migration,
      $container->get('config.factory'),
      $container->get('language_manager')
    );
  }

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    if ($this->isTranslationDestination()) {
      $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();
    $ids[] = $this->config->getName();
    if ($this->isTranslationDestination()) {
      $ids[] = $row->getDestinationProperty('langcode');
    }

  protected function getEntity(Row $row, array $old_destination_id_values) {
    // For stub rows, there is no real file to deal with, let the stubbing     // process take its default path.     if ($row->isStub()) {
      return parent::getEntity($row$old_destination_id_values);
    }

    // By default the entity key (fid) would be used, but we want to make sure     // we're loading the matching URI.     $destination = $row->getDestinationProperty('uri');
    if (empty($destination)) {
      throw new MigrateException('Destination property uri not provided');
    }
    $entity = $this->storage->loadByProperties(['uri' => $destination]);
    if ($entity) {
      return reset($entity);
    }
    else {
      return parent::getEntity($row$old_destination_id_values);
    }
  }

  
          // destination.           $is_source = empty($matches[1]);
          // Remove the possible escaping and do not lose the terminating           // non-@ either.           return str_replace('@@', '@', $matches[2]) . $matches[3];
        }$property);
      }
      if ($is_source) {
        $return[$orig_property] = $this->getSourceProperty($property);
      }
      else {
        $return[$orig_property] = $this->getDestinationProperty($property);
      }
    }
    return $return;
  }

  /** * Sets the Migrate ID mappings. * * @param array $id_map * An array of mappings between source ID and destination ID. */
  
return [
      'uid' => 'The users.uid for this set.',
      'source' => 'The shortcut_set.set_name that will be displayed for this user.',
    ];
  }

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    /** @var \Drupal\shortcut\ShortcutSetInterface $set */
    $set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name'));
    /** @var \Drupal\user\UserInterface $account */
    $account = User::load($row->getDestinationProperty('uid'));
    $this->shortcutSetStorage->assignUser($set$account);

    return [$set->id()$account->id()];
  }

}

  protected function getEntity(Row $row, array $old_destination_id_values) {
    $revision_id = $old_destination_id_values
      ? $old_destination_id_values[1]
      : $row->getDestinationProperty($this->getKey('revision'));
    // If we are re-running a migration with set revision IDs and the     // destination revision ID already exists then do not create a new revision.     if (!empty($revision_id) && ($entity = $this->storage->loadRevision($revision_id))) {
      $entity->setNewRevision(FALSE);
    }
    elseif (($entity_id = $row->getDestinationProperty($this->getKey('id'))) && ($entity = $this->storage->load($entity_id))) {
      // We want to create a new entity. Set enforceIsNew() FALSE is necessary       // to properly save a new entity while setting the ID. Without it, the       // system would see that the ID is already set and assume it is an update.       $entity->enforceIsNew(FALSE);
      // Intentionally create a new revision. Setting new revision TRUE here may
$plugin_definition,
      $migration,
      $container->get('config.factory')
    );
  }

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    $imported = FALSE;
    $config = $this->configFactory->getEditable($row->getDestinationProperty('configuration_name'));
    $theme_settings = $row->getDestination();
    // Remove keys not in theme settings.     unset($theme_settings['configuration_name']);
    unset($theme_settings['theme_name']);
    unset($theme_settings['legacy_theme_name']);
    if (isset($theme_settings)) {
      theme_settings_convert_to_config($theme_settings$config);
      $config->save();
      $imported = TRUE;
    }
    return $imported;
  }

class EntityBlock extends EntityConfigBase {

  /** * {@inheritdoc} */
  protected function getEntityId(Row $row) {
    // Try to find the block by its plugin ID and theme.     $properties = [
      'plugin' => $row->getDestinationProperty('plugin'),
      'theme' => $row->getDestinationProperty('theme'),
    ];
    $blocks = array_keys($this->storage->loadByProperties($properties));
    return reset($blocks);
  }

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    try {
      

  public function getBundle(Row $row) {
    $default_bundle = $this->configuration['default_bundle'] ?? '';
    $bundle_key = $this->getKey('bundle');
    return $row->getDestinationProperty($bundle_key) ?: $default_bundle;
  }

  /** * {@inheritdoc} */
  public function fields() {
    // TODO: Implement fields() method.   }

  /** * Creates or loads an entity. * * @param \Drupal\migrate\Row $row * The row object. * @param array $old_destination_id_values * The old destination IDs. * * @return \Drupal\Core\Entity\EntityInterface * The entity we are importing into. */

  protected function getEntity(Row $row, array $old_destination_id_values) {
    $revision_id = $old_destination_id_values ?
      reset($old_destination_id_values) :
      $row->getDestinationProperty($this->getKey('revision'));
    if (!empty($revision_id) && ($entity = $this->storage->loadRevision($revision_id))) {
      $entity->setNewRevision(FALSE);
    }
    else {
      $entity_id = $row->getDestinationProperty($this->getKey('id'));
      $entity = $this->storage->load($entity_id);

      // If we fail to load the original entity something is wrong and we need       // to return immediately.       if (!$entity) {
        return FALSE;
      }

  protected static function getEntityTypeId($plugin_id) {
    return 'node';
  }

  /** * {@inheritdoc} */
  protected function updateEntity(EntityInterface $entity, Row $row) {
    if ($entity->book) {
      $book = $row->getDestinationProperty('book');
      foreach ($book as $key => $value) {
        $entity->book[$key] = $value;
      }
    }
    else {
      $entity->book = $row->getDestinationProperty('book');
    }
    return parent::updateEntity($entity$row);
  }

}

  public function import(Row $row, array $old_destination_id_values = []) {
    if ($row->isStub()) {
      throw new MigrateException('Config entities can not be stubbed.');
    }
    $this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
    $ids = $this->getIds();
    $id_key = $this->getKey('id');
    if (count($ids) > 1) {
      // Ids is keyed by the key name so grab the keys.       $id_keys = array_keys($ids);
      if (!$row->getDestinationProperty($id_key)) {
        // Set the ID into the destination in for form "val1.val2.val3".         $row->setDestinationProperty($id_key$this->generateId($row$id_keys));
      }
    }
    $entity = $this->getEntity($row$old_destination_id_values);
    // Translations are already saved in updateEntity by configuration override.     if (!$this->isTranslationDestination()) {
      $entity->save();
    }
    if (count($ids) > 1) {
      // This can only be a config entity, content entities have their ID key

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

}
// 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'));
  }

  /** * Tests getting source and destination properties. * * @param string $key * The key to look up. * @param string $expected_value * The expected value. * * @dataProvider getDataProvider * @covers ::get */
$plugins[$key][0]->expects($this->once())
        ->method('transform')
        ->willReturn($value);
    }
    $this->migration->expects($this->once())
      ->method('getProcessPlugins')
      ->with(NULL)
      ->willReturn($plugins);
    $row = new Row();
    $this->executable->processRow($row);
    foreach ($expected as $key => $value) {
      $this->assertSame($row->getDestinationProperty($key)$value);
    }
    $this->assertSameSize($expected$row->getDestination());
  }

  /** * Tests the processRow method with an empty pipeline. */
  public function testProcessRowEmptyPipeline() {
    $this->migration->expects($this->once())
      ->method('getProcessPlugins')
      ->with(NULL)
      

  protected function transformKey($key, MigrateExecutableInterface $migrate_executable, Row $row) {
    $process = ['key' => $this->configuration['key']];
    $migrate_executable->processRow($row$process$key);
    return $row->getDestinationProperty('key');
  }

  /** * {@inheritdoc} */
  public function multiple() {
    return TRUE;
  }

}
Home | Imprint | This part of the site doesn't use cookies.