Commit 4984acbe authored by benjifisher's avatar benjifisher Committed by Derimagia

Issue #3021648 by benjifisher, selwynpolit: Add a migrate plugin to debug one process step

parent d56b84fe
<?php
namespace Drupal\migrate_devel\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate\MigrateSkipRowException;
/**
* Debug the process pipeline.
*
* Prints the input value, assuming that you are running the migration from the
* command line, and sends it to the next step in the pipeline unaltered.
*
* Available configuration keys:
* - label: (optional) a string to print before the debug output. Include any
* trailing punctuation or space characters.
* - multiple: (optional) set to TRUE to ask the next step in the process
* pipeline to process array values individually, like the multiple_values
* plugin from the Migrate Plus module.
*
* Examples:
*
* @code
* process:
* field_tricky:
* -
* plugin: debug
* source: whatever
* -
* plugin: next
* @endcode
*
* This will print the source before passing it to the next plugin.
*
* @code
* process:
* field_tricky:
* -
* plugin: debug
* source: whatever
* label: 'Step 1: '
* multiple: true
* -
* plugin: next
* @endcode
*
* This does the same thing, but ensures that the next plugin will be called
* once for each item in the source, if the source is an array.
* It will also print "Debug Step 1: " before printing the source.
*
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @MigrateProcessPlugin(
* id = "debug",
* handle_multiples = TRUE
* )
*/
class Debug extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (isset($this->configuration['label'])) {
print_r($this->configuration['label']);
}
print_r($value);
if (!is_array($value)) {
print_r(PHP_EOL);
}
return $value;
}
/**
* {@inheritdoc}
*/
public function multiple() {
return !empty($this->configuration['multiple']);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment