Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookFieldFormatterInfo.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookFieldFormatterInfo.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookFieldFormatterInfo.php
new file mode 100644 (file)
index 0000000..0eebc62
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
+
+use Drupal\drupalmoduleupgrader\ConverterBase;
+use Drupal\drupalmoduleupgrader\TargetInterface;
+use Drupal\drupalmoduleupgrader\Utility\StringTransformTrait;
+
+/**
+ * @Converter(
+ *  id = "hook_field_formatter_info",
+ *  description = @Translation("Creates formatter class templates from hook_field_formatter_info()."),
+ *  hook = "hook_field_formatter_info"
+ * )
+ */
+class HookFieldFormatterInfo extends ConverterBase {
+
+  use StringTransformTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function convert(TargetInterface $target) {
+    try {
+      $formatters = $this->executeHook($target, $this->pluginDefinition['hook']);
+    }
+    catch (\LogicException $e) {
+      $this->log->warning($e->getMessage(), [
+        'target' => $target->id(),
+        'hook' => $this->pluginDefinition['hook'],
+      ]);
+      return;
+    }
+
+    foreach ($formatters as $id => $formatter) {
+      $render = [
+        '#module' => $target->id(),
+        '#class' => $this->toTitleCase($id),
+        '#theme' => 'dmu_formatter',
+        '#info' => [
+          'id' => $id,
+          'label' => $formatter['label'],
+          'description' => $formatter['description'] ?: NULL,
+          'field_types' => $formatter['field types'],
+        ],
+      ];
+      $this->writeClass($target, $this->parse($render));
+    }
+  }
+
+}