ParagraphsProcessOnValue.php in Paragraphs 8
File
src/Plugin/migrate/process/ParagraphsProcessOnValue.php
View source
<?php
namespace Drupal\paragraphs\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
class ParagraphsProcessOnValue extends ProcessPluginBase {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (empty($this->configuration['source_value'])) {
throw new \InvalidArgumentException("Required argument 'source_value' not set for paragraphs_process_on_value plugin");
}
if (!isset($this->configuration['expected_value'])) {
throw new \InvalidArgumentException("Required argument 'expected_value' not set for paragraphs_process_on_value plugin");
}
if (empty($this->configuration['process']) || !is_array($this->configuration['process'])) {
throw new \InvalidArgumentException("Required argument 'process' not set or invalid for paragraphs_process_on_value plugin");
}
$source_value = $row
->getSourceProperty($this->configuration['source_value']);
if (is_null($source_value)) {
return $value;
}
if ($source_value === $this->configuration['expected_value']) {
$process = $this->configuration['process'];
$source = $row
->getSource();
$source['paragraphs_process_on_value_source_field'] = $value;
if (array_key_exists('plugin', $process)) {
if (empty($process['source'])) {
$process['source'] = 'paragraphs_process_on_value_source_field';
}
}
else {
if (empty($process[0]['source'])) {
$process[0]['source'] = 'paragraphs_process_on_value_source_field';
}
}
$source = $row
->getSource();
$source['paragraphs_process_on_value_source_field'] = $value;
$new_row = new Row($source, []);
$migrate_executable
->processRow($new_row, [
$destination_property => $process,
]);
return $new_row
->getDestinationProperty($destination_property);
}
else {
return $value;
}
}
public function defaultConfiguration() {
return [
'source_value' => '',
'expected_value' => '',
'process' => [],
] + parent::defaultConfiguration();
}
}