Commit 0bff6245 authored by catch's avatar catch

Issue #2872812 by rakesh.gectcr, cosmicdreams, mikeryan: Create process plugin to log a message

parent 68d8cd26
<?php
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Logs values without changing them.
*
* The log plugin will log the values that are being processed by other plugins.
*
* Example:
* @code
* process:
* bar:
* plugin: log
* source: foo
* @endcode
*
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @MigrateProcessPlugin(
* id = "log"
* )
*/
class Log extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Log the value.
$migrate_executable->saveMessage($value);
// Pass through the same value we received.
return $value;
}
}
<?php
namespace Drupal\Tests\migrate\Kernel\Plugin;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* Tests the Log process plugin.
*
* @group migrate
*/
class LogTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['migrate'];
/**
* Test the Log plugin
*/
public function testLog() {
$plugin = \Drupal::service('plugin.manager.migrate.process')
->createInstance('log');
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
$row = new Row();
$log_message = "Testing the log message";
//Ensure the log is getting saved
$saved_message = $plugin->transform($log_message, $executable, $row, 'buffalo');
$this->assertSame($log_message, $saved_message);
}
}
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