Browse Source

Added README and documentation about terms hierarchy.

Frederic G. MARAND 7 years ago
parent
commit
54bd1f68f3
2 changed files with 44 additions and 0 deletions
  1. 33 0
      README.md
  2. 11 0
      src/Plugin/migrate/source/ReinstallTermSource.php

+ 33 - 0
README.md

@@ -0,0 +1,33 @@
+# Reinstall
+
+## Usage notes
+
+### Support for term hierarchy
+
+This mechanism supports multiple parents on terms. However, it needs the 
+migrations to include its callback, within a process pipeline like:
+
+```yaml
+# In migrate_plus.migration.reinstall_terms_foo
+process:
+  parent_id:
+    -
+      plugin: skip_on_empty
+      method: process
+      source: parent
+    -
+      # This step is needed to transform the terms parents to usable values.
+      # Without it, all terms will be at level 0 in the target vocabulary.
+      plugin: callback
+      callable:
+        - '\Drupal\reinstall\Plugin\migrate\source\ReinstallTermSource'
+        - 'getParent'
+    -
+      plugin: migration
+      # Notice the reference to the current migration.
+      migration: reinstall_terms_foo
+  parent:
+    plugin: default_value
+    default_value: 0
+    source: '@parent_id'
+```

+ 11 - 0
src/Plugin/migrate/source/ReinstallTermSource.php

@@ -68,6 +68,17 @@ class ReinstallTermSource extends SimpleSource {
     return $ids;
   }
 
+  /**
+   * Obtain the term parents from either of their two formats.
+   *
+   * @param mixed $source
+   *   A parent, from the migration pipeline.
+   *
+   * @return mixed
+   *   The parent, as its target_id.
+   *
+   * @see (reinstall)/README.md
+   */
   public static function getParent($source) {
     if (is_scalar($source)) {
       return $source;