3 namespace Drupal\migrate_plus\Plugin\migrate\process;
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\MigrateSkipProcessException;
8 use Drupal\migrate\MigrateSkipRowException;
9 use Drupal\migrate\ProcessPluginBase;
10 use Drupal\migrate\Row;
13 * If the source evaluates to a configured value, skip processing or whole row.
15 * @MigrateProcessPlugin(
16 * id = "skip_on_value"
19 class SkipOnValue extends ProcessPluginBase {
24 public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
25 if (empty($this->configuration['value']) && !array_key_exists('value', $this->configuration)) {
26 throw new MigrateException('Skip on value plugin is missing value configuration.');
29 if (is_array($this->configuration['value'])) {
30 foreach ($this->configuration['value'] as $skipValue) {
31 if ($this->compareValue($value, $skipValue, !isset($this->configuration['not_equals']))) {
32 throw new MigrateSkipRowException();
36 elseif ($this->compareValue($value, $this->configuration['value'], !isset($this->configuration['not_equals']))) {
37 throw new MigrateSkipRowException();
46 public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
47 if (empty($this->configuration['value']) && !array_key_exists('value', $this->configuration)) {
48 throw new MigrateException('Skip on value plugin is missing value configuration.');
51 if (is_array($this->configuration['value'])) {
52 foreach ($this->configuration['value'] as $skipValue) {
53 if ($this->compareValue($value, $skipValue, !isset($this->configuration['not_equals']))) {
54 throw new MigrateSkipProcessException();
58 elseif ($this->compareValue($value, $this->configuration['value'], !isset($this->configuration['not_equals']))) {
59 throw new MigrateSkipProcessException();
66 * Compare values to see if they are equal.
71 * Value to compare against.
73 * Compare as equal or not equal.
76 * True if the compare successfully, FALSE otherwise.
78 protected function compareValue($value, $skipValue, $equal = TRUE) {
80 return (string) $value == (string) $skipValue;
83 return (string) $value != (string) $skipValue;