You are here

public function StaticMap::transform in Drupal 9

Same name and namespace in other branches
  1. 8 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

3 calls to StaticMap::transform()
BlockRegion::transform in core/modules/block/src/Plugin/migrate/process/BlockRegion.php
Performs the associated process.
FieldType::transform in core/modules/field/src/Plugin/migrate/process/FieldType.php
Performs the associated process.
FilterID::transform in core/modules/filter/src/Plugin/migrate/process/FilterID.php
Performs the associated process.
3 methods override StaticMap::transform()
BlockRegion::transform in core/modules/block/src/Plugin/migrate/process/BlockRegion.php
Performs the associated process.
FieldType::transform in core/modules/field/src/Plugin/migrate/process/FieldType.php
Performs the associated process.
FilterID::transform in core/modules/filter/src/Plugin/migrate/process/FilterID.php
Performs the associated process.

File

core/modules/migrate/src/Plugin/migrate/process/StaticMap.php, line 153

Class

StaticMap
Changes the source 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 = [
      $value,
    ];
  }
  $new_value = NestedArray::getValue($this->configuration['map'], $new_value, $key_exists);
  if (!$key_exists) {
    if (array_key_exists('default_value', $this->configuration)) {
      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(sprintf("No static mapping found for '%s' and no default value provided for destination '%s'.", Variable::export($value), $destination_property));
    }
    else {
      return $value;
    }
  }
  return $new_value;
}