Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookFieldFormatterInfo.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
4
5 use Drupal\drupalmoduleupgrader\ConverterBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
7 use Drupal\drupalmoduleupgrader\Utility\StringTransformTrait;
8
9 /**
10  * @Converter(
11  *  id = "hook_field_formatter_info",
12  *  description = @Translation("Creates formatter class templates from hook_field_formatter_info()."),
13  *  hook = "hook_field_formatter_info"
14  * )
15  */
16 class HookFieldFormatterInfo extends ConverterBase {
17
18   use StringTransformTrait;
19
20   /**
21    * {@inheritdoc}
22    */
23   public function convert(TargetInterface $target) {
24     try {
25       $formatters = $this->executeHook($target, $this->pluginDefinition['hook']);
26     }
27     catch (\LogicException $e) {
28       $this->log->warning($e->getMessage(), [
29         'target' => $target->id(),
30         'hook' => $this->pluginDefinition['hook'],
31       ]);
32       return;
33     }
34
35     foreach ($formatters as $id => $formatter) {
36       $render = [
37         '#module' => $target->id(),
38         '#class' => $this->toTitleCase($id),
39         '#theme' => 'dmu_formatter',
40         '#info' => [
41           'id' => $id,
42           'label' => $formatter['label'],
43           'description' => $formatter['description'] ?: NULL,
44           'field_types' => $formatter['field types'],
45         ],
46       ];
47       $this->writeClass($target, $this->parse($render));
48     }
49   }
50
51 }