Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookLibrary.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookLibrary.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookLibrary.php
new file mode 100644 (file)
index 0000000..d1a8e5f
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
+
+use Drupal\drupalmoduleupgrader\ConverterBase;
+use Drupal\drupalmoduleupgrader\TargetInterface;
+
+/**
+ * @Converter(
+ *  id = "hook_library",
+ *  description = @Translation("Converts Drupal 7's hook_library() to YAML."),
+ *  hook = "hook_library"
+ * )
+ */
+class HookLibrary extends ConverterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function convert(TargetInterface $target) {
+    try {
+      $libraries = $this->executeHook($target, $this->pluginDefinition['hook']);
+    }
+    catch (\LogicException $e) {
+      return;
+    }
+
+    foreach ($libraries as $id => &$lib) {
+      if (isset($lib['website'])) {
+        $lib['remote'] = $lib['website'];
+        unset($lib['website']);
+      }
+
+      if (isset($lib['dependencies'])) {
+        $lib['dependencies'] = array_map(function(array $dependency) {
+          if ($dependency[0] == 'system') {
+            $dependency[0] == 'core';
+          }
+          return implode('/', $dependency);
+        }, $lib['dependencies']);
+      }
+    }
+
+    $this->writeInfo($target, 'libraries', $libraries);
+  }
+
+}