Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / migrate_plus / src / Plugin / migrate / process / SkipOnValue.php
index 0e8083acb5dd5ef55c051b1cf39dfbee31227d4e..1a0c8f545c5996f3c5708da619f918dd4ef60168 100644 (file)
@@ -1,10 +1,5 @@
 <?php
 
-/**
- * @file
- * Contains \Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue.
- */
-
 namespace Drupal\migrate_plus\Plugin\migrate\process;
 
 use Drupal\migrate\MigrateException;
@@ -20,6 +15,44 @@ use Drupal\migrate\Row;
  * @MigrateProcessPlugin(
  *   id = "skip_on_value"
  * )
+ *
+ * Available configuration keys:
+ * - value: An single value or array of values against which the source value
+ *   should be compared.
+ * - not_equals: (optional) If set, skipping occurs when values are not equal.
+ * - method: What to do if the input value is empty. Possible values:
+ *   - row: Skips the entire row when an empty value is encountered.
+ *   - process: Prevents further processing of the input property when the value
+ *     is empty.
+ *
+ * Examples:
+ *
+ * Example usage with minimal configuration:
+ * @code
+ *   type:
+ *     plugin: skip_on_value
+ *     source: content_type
+ *     method: row
+ *     value: blog
+ * @endcode
+ *
+ * The above example will skip processing the input property if the content_type
+ * source field equals "blog".
+ *
+ * Example usage with full configuration:
+ * @code
+ *   type:
+ *     plugin: skip_on_value
+ *     not_equals: true
+ *     source: content_type
+ *     method: row
+ *     value:
+ *       - article
+ *       - testimonial
+ * @endcode
+ *
+ * The above example will skip processing any row for which the source row's
+ * content type field is not "article" or "testimonial".
  */
 class SkipOnValue extends ProcessPluginBase {
 
@@ -32,10 +65,15 @@ class SkipOnValue extends ProcessPluginBase {
     }
 
     if (is_array($this->configuration['value'])) {
+      $value_in_array = FALSE;
+      $not_equals = isset($this->configuration['not_equals']);
+
       foreach ($this->configuration['value'] as $skipValue) {
-        if ($this->compareValue($value, $skipValue, !isset($this->configuration['not_equals']))) {
-          throw new MigrateSkipRowException();
-        }
+        $value_in_array |= $this->compareValue($value, $skipValue);
+      }
+
+      if (($not_equals && !$value_in_array) || (!$not_equals && $value_in_array)) {
+        throw new MigrateSkipRowException();
       }
     }
     elseif ($this->compareValue($value, $this->configuration['value'], !isset($this->configuration['not_equals']))) {
@@ -54,10 +92,15 @@ class SkipOnValue extends ProcessPluginBase {
     }
 
     if (is_array($this->configuration['value'])) {
+      $value_in_array = FALSE;
+      $not_equals = isset($this->configuration['not_equals']);
+
       foreach ($this->configuration['value'] as $skipValue) {
-        if ($this->compareValue($value, $skipValue, !isset($this->configuration['not_equals']))) {
-          throw new MigrateSkipProcessException();
-        }
+        $value_in_array |= $this->compareValue($value, $skipValue);
+      }
+
+      if (($not_equals && !$value_in_array) || (!$not_equals && $value_in_array)) {
+        throw new MigrateSkipProcessException();
       }
     }
     elseif ($this->compareValue($value, $this->configuration['value'], !isset($this->configuration['not_equals']))) {
@@ -70,11 +113,11 @@ class SkipOnValue extends ProcessPluginBase {
   /**
    * Compare values to see if they are equal.
    *
-   * @param $value
-   *   Actual value
-   * @param $skipValue
+   * @param mixed $value
+   *   Actual value.
+   * @param mixed $skipValue
    *   Value to compare against.
-   * @param $equal
+   * @param bool $equal
    *   Compare as equal or not equal.
    *
    * @return bool