You are here

public function DomMigrationLookup::transform in Migrate Plus 8.5

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

Overrides DomStrReplace::transform

File

src/Plugin/migrate/process/DomMigrationLookup.php, line 152

Class

DomMigrationLookup
String replacements on a source dom based on migration lookup.

Namespace

Drupal\migrate_plus\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  $this
    ->init($value, $destination_property);
  $this->transformParameters = [
    'migrate_executable' => $migrate_executable,
    'row' => $row,
    'destination_property' => $destination_property,
  ];
  foreach ($this->xpath
    ->query($this->configuration['xpath']) as $html_node) {
    $subject = $this
      ->getSubject($html_node);
    if (empty($subject)) {

      // Could not find subject, skip processing.
      continue;
    }
    $search = $this
      ->getSearch();
    if (!preg_match($search, $subject, $matches)) {

      // No match found, skip processing.
      continue;
    }
    $id = $matches[1];

    // Walk through defined migrations looking for a map.
    foreach ($this->configuration['migrations'] as $migration_name => $configuration) {
      $mapped_id = $this
        ->migrationLookup($id, $migration_name);
      if (!is_null($mapped_id)) {

        // Not using getReplace(), since this implementation depends on the
        // migration.
        $replace = str_replace('[mapped-id]', $mapped_id, $configuration['replace']);
        $this
          ->doReplace($html_node, $search, $replace, $subject);
        break;
      }
    }
  }
  return $this->document;
}