function StaticMap::transform

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 145

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) {
  if ($value === NULL) {
    if (array_key_exists('', $this->configuration['map'])) {
      if (array_key_exists('default_value', $this->configuration) && $this->configuration['default_value'] === $this->configuration['map']['']) {
        return $this->configuration['default_value'];
      }
      @trigger_error('Relying on mapping NULL values via an empty string map key in ' . __CLASS__ . '::transform() is deprecated in drupal:11.3.0 and will trigger a Drupal\\migrate\\MigrateSkipRowException from drupal:12.0.0. Set the empty string map value as the "default_value" in the plugin configuration. See https://www.drupal.org/node/3557003', E_USER_DEPRECATED);
      // Preserve the current behavior of returning the value mapped to an
      // empty string for NULL.
      return $this->configuration['map'][''];
    }
    if (array_key_exists('default_value', $this->configuration)) {
      return $this->configuration['default_value'];
    }
    if (!empty($this->configuration['bypass'])) {
      return NULL;
    }
    throw new MigrateSkipRowException(sprintf("No static mapping possible for NULL and no default value provided for destination '%s'.", $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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.