public function Log::transform in Drupal 9
Same name and namespace in other branches
- 8 core/modules/migrate/src/Plugin/migrate/process/Log.php \Drupal\migrate\Plugin\migrate\process\Log::transform()
- 10 core/modules/migrate/src/Plugin/migrate/process/Log.php \Drupal\migrate\Plugin\migrate\process\Log::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
File
- core/
modules/ migrate/ src/ Plugin/ migrate/ process/ Log.php, line 33
Class
- Log
- Logs values without changing them.
Namespace
Drupal\migrate\Plugin\migrate\processCode
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$is_object = is_object($value);
if (is_null($value) || is_bool($value)) {
$export = var_export($value, TRUE);
}
elseif (is_float($value)) {
$export = sprintf('%f', $value);
}
elseif ($is_object && method_exists($value, 'toString')) {
$export = print_r($value
->toString(), TRUE);
}
elseif ($is_object && method_exists($value, 'toArray')) {
$export = print_r($value
->toArray(), TRUE);
}
elseif (is_string($value) || is_numeric($value) || is_array($value)) {
$export = print_r($value, TRUE);
}
elseif ($is_object && method_exists($value, '__toString')) {
$export = print_r((string) $value, TRUE);
}
else {
$export = NULL;
}
$class_name = $export !== NULL && $is_object ? $class_name = get_class($value) . ":\n" : '';
$message = $export === NULL ? "Unable to log the value for '{$destination_property}'" : "'{$destination_property}' value is {$class_name}'{$export}'";
// Log the value.
$migrate_executable
->saveMessage($message);
// Pass through the same value we received.
return $value;
}