Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / migrate / src / Plugin / migrate / process / MigrationLookup.php
index 5f144a4df35e7f4b7fdd87d9c99962bae984f398..e8a075606e68194d8a65347b84bfb61f1f262b32 100644 (file)
@@ -34,10 +34,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  *
  * Examples:
  *
- * Consider a node migration, where you want to maintain authorship. If you have
- * migrated the user accounts in a migration named "users", you would specify
- * the following:
- *
+ * Consider a node migration, where you want to maintain authorship. Let's
+ * assume that users are previously migrated in a migration named 'users'. The
+ * 'users' migration saved the mapping between the source and destination IDs in
+ * a map table. The node migration example below maps the node 'uid' property so
+ * that we first take the source 'author' value and then do a lookup for the
+ * corresponding Drupal user ID from the map table.
  * @code
  * process:
  *   uid:
@@ -46,15 +48,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  *     source: author
  * @endcode
  *
- * This takes the value of the author property in the source data, and looks it
- * up in the map table associated with the users migration, returning the
- * resulting user ID and assigning it to the destination uid property.
- *
  * The value of 'migration' can be a list of migration IDs. When using multiple
  * migrations it is possible each use different source identifiers. In this
  * case one can use source_ids which is an array keyed by the migration IDs
- * and the value is a list of source properties.
- *
+ * and the value is a list of source properties. See example below.
  * @code
  * process:
  *   uid:
@@ -73,8 +70,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  * map it will create a stub entity for the relationship to use. This stub is
  * generated by the migration provided. In the case of multiple migrations the
  * first value of the migration list will be used, but you can select the
- * migration you wish to use by using the stub_id configuration key:
- *
+ * migration you wish to use by using the stub_id configuration key. The example
+ * below uses 'members' migration to create stub entities.
  * @code
  * process:
  *   uid:
@@ -85,12 +82,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  *     stub_id: members
  * @endcode
  *
- * In the above example, the value of stub_id selects the members migration to
- * create any stub entities.
- *
  * To prevent the creation of a stub entity when no relationship is found in the
- * migration map, use no_stub:
- *
+ * migration map, 'no_stub' configuration can be used as shown below.
  * @code
  * process:
  *   uid:
@@ -161,10 +154,6 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
     if (!is_array($migration_ids)) {
       $migration_ids = [$migration_ids];
     }
-    if (!is_array($value)) {
-      $value = [$value];
-    }
-    $this->skipOnEmpty($value);
     $self = FALSE;
     /** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
     $destination_ids = NULL;
@@ -176,13 +165,15 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
       }
       if (isset($this->configuration['source_ids'][$migration_id])) {
         $configuration = ['source' => $this->configuration['source_ids'][$migration_id]];
-        $source_id_values[$migration_id] = $this->processPluginManager
+        $value = $this->processPluginManager
           ->createInstance('get', $configuration, $this->migration)
           ->transform(NULL, $migrate_executable, $row, $destination_property);
       }
-      else {
-        $source_id_values[$migration_id] = $value;
+      if (!is_array($value)) {
+        $value = [$value];
       }
+      $this->skipOnEmpty($value);
+      $source_id_values[$migration_id] = $value;
       // Break out of the loop as soon as a destination ID is found.
       if ($destination_ids = $migration->getIdMap()->lookupDestinationId($source_id_values[$migration_id])) {
         break;