function Extract::transform

Same name in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/migrate/process/Extract.php \Drupal\migrate\Plugin\migrate\process\Extract::transform()
  2. 10 core/modules/migrate/src/Plugin/migrate/process/Extract.php \Drupal\migrate\Plugin\migrate\process\Extract::transform()
  3. 11.x core/modules/migrate/src/Plugin/migrate/process/Extract.php \Drupal\migrate\Plugin\migrate\process\Extract::transform()

Overrides ProcessPluginBase::transform

File

core/modules/migrate/src/Plugin/migrate/process/Extract.php, line 70

Class

Extract
Extracts a value from an array.

Namespace

Drupal\migrate\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    if (!is_array($value)) {
        throw new MigrateException(sprintf("Input should be an array, instead it was of type '%s'", gettype($value)));
    }
    $new_value = NestedArray::getValue($value, $this->configuration['index'], $key_exists);
    if (!$key_exists) {
        if (array_key_exists('default', $this->configuration)) {
            $new_value = $this->configuration['default'];
        }
        else {
            throw new MigrateException(sprintf("Array index missing, extraction failed for '%s'. Consider adding a `default` key to the configuration.", Variable::export($value)));
        }
    }
    return $new_value;
}

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