/** * Tests the filter_id plugin. * * @param mixed $value * The input value to the plugin. * @param string $expected_value * The output value expected from the plugin. * @param string $invalid_id * (optional) The invalid plugin ID which is expected to be logged by the * MigrateExecutable object. * * @dataProvider testProvider * * @covers ::transform */ public function test($value, $expected_value, $invalid_id = NULL) { $configuration = ['bypass' => TRUE, 'map' => ['foo' => 'filter_html', 'baz' => 'php_code']]; $plugin = FilterID::create($this->container, $configuration, 'filter_id', []); if (isset($invalid_id)) { $this->executable->expects($this->exactly(1))->method('saveMessage')->with('Filter ' . $invalid_id . ' could not be mapped to an existing filter plugin; defaulting to filter_null.', MigrationInterface::MESSAGE_WARNING); } $row = new Row(); $output_value = $plugin->transform($value, $this->executable, $row, 'foo'); $this->assertSame($expected_value, $output_value); }
/** * Runs a process pipeline on each destination list item. */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $return = array(); if (!is_array($value)) { $value = [$value]; } // All processes are applied to a single field. $process = [$this->configuration['process']]; foreach ($value as $key => $new_value) { $new_row = new Row(array(), array()); $migrate_executable->processRow($new_row, $process, $new_value); $destination = $new_row->getDestination(); // Getting the last value from the process chain. $return[$key] = end($destination); } return $return; }
/** * Runs the process pipeline for the current key. * * @param string|int $key * The current key. * @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable * The migrate executable helper class. * @param \Drupal\migrate\Row $row * The current row after processing. * * @return mixed * The transformed key. */ protected function transformKey($key, MigrateExecutableInterface $migrate_executable, Row $row) { $process = array('key' => $this->configuration['key']); $migrate_executable->processRow($row, $process, $key); return $row->getDestinationProperty('key'); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $result = TRUE; try { $result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', array($row, $this, $this->migration)); $result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', array($row, $this, $this->migration)); // We will skip if any hook returned FALSE. $skip = $result_hook && in_array(FALSE, $result_hook) || $result_named_hook && in_array(FALSE, $result_named_hook); $save_to_map = TRUE; } catch (MigrateSkipRowException $e) { $skip = TRUE; $save_to_map = $e->getSaveToMap(); } // We're explicitly skipping this row - keep track in the map table. if ($skip) { // Make sure we replace any previous messages for this item with any // new ones. $id_map = $this->migration->getIdMap(); $id_map->delete($this->currentSourceIds, TRUE); $this->migrateExecutable->saveQueuedMessages(); if ($save_to_map) { $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED, $this->migrateExecutable->rollbackAction); $this->currentRow = NULL; $this->currentSourceIds = NULL; } $result = FALSE; } elseif ($this->trackChanges) { // When tracking changed data, We want to quietly skip (rather than // "ignore") rows with changes. The caller needs to make that decision, // so we need to provide them with the necessary information (before and // after hashes). $row->rehash(); } return $result; }