Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / migrate_plus / src / Plugin / migrate / process / SingleValue.php
diff --git a/web/modules/contrib/migrate_plus/src/Plugin/migrate/process/SingleValue.php b/web/modules/contrib/migrate_plus/src/Plugin/migrate/process/SingleValue.php
new file mode 100644 (file)
index 0000000..2583a90
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+namespace Drupal\migrate_plus\Plugin\migrate\process;
+
+use Drupal\migrate\MigrateExecutableInterface;
+use Drupal\migrate\ProcessPluginBase;
+use Drupal\migrate\Row;
+
+/**
+ * Treat an array of values as a single value.
+ *
+ * @code
+ * process:
+ *   field_authors:
+ *     -
+ *       plugin: explode
+ *       delimiter: ', '
+ *       source: authors
+ *     -
+ *       plugin: single_value
+ * @endcode
+ *
+ * Assume the "authors" field contains comma separated author names.
+ *
+ * After the explode, we end up with each author name as an individual value.
+ * But if we want to perform a sort on all values using a callback, we will
+ * need to send all the values to a callable together as an array of author
+ * names. Calling the "single_value" plugin in such a case will combine all the
+ * values into a single array for the next plugin.
+ *
+ * @MigrateProcessPlugin(
+ *   id = "single_value",
+ *   handle_multiples = TRUE
+ * )
+ */
+class SingleValue extends ProcessPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+    return $value;
+  }
+
+}