You are here

public function StaticMap::transform in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/src/Plugin/migrate/process/StaticMap.php \Drupal\migrate\Plugin\migrate\process\StaticMap::transform()

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 ProcessPluginBase::transform

1 call to StaticMap::transform()
FieldType::transform in core/modules/field/src/Plugin/migrate/process/d6/FieldType.php
Performs the associated process.
1 method overrides StaticMap::transform()
FieldType::transform in core/modules/field/src/Plugin/migrate/process/d6/FieldType.php
Performs the associated process.

File

core/modules/migrate/src/Plugin/migrate/process/StaticMap.php, line 31
Contains \Drupal\migrate\Plugin\migrate\process\StaticMap.

Class

StaticMap
This plugin changes the current value based on a static lookup map.

Namespace

Drupal\migrate\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  $new_value = $value;
  if (is_array($value)) {
    if (!$value) {
      throw new MigrateException('Can not lookup without a value.');
    }
  }
  else {
    $new_value = array(
      $value,
    );
  }
  $new_value = NestedArray::getValue($this->configuration['map'], $new_value, $key_exists);
  if (!$key_exists) {
    if (isset($this->configuration['default_value'])) {
      if (!empty($this->configuration['bypass'])) {
        throw new MigrateException('Setting both default_value and bypass is invalid.');
      }
      return $this->configuration['default_value'];
    }
    if (empty($this->configuration['bypass'])) {
      throw new MigrateSkipRowException();
    }
    else {
      return $value;
    }
  }
  return $new_value;
}