Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookFieldWidgetInfo.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_widget_info",
12  *  description = @Translation("Creates formatter class templates from hook_field_widget_info()."),
13  *  hook = "hook_field_widget_info"
14  * )
15  */
16 class HookFieldWidgetInfo extends ConverterBase {
17
18   use StringTransformTrait;
19
20   /**
21    * {@inheritdoc}
22    */
23   public function convert(TargetInterface $target) {
24     try {
25       $widgets = $this->executeHook($target, $this->pluginDefinition['hook']);
26     }
27     catch (\LogicException $e) {
28       $this->logger->warning($e->getMessage(), [
29         'target' => $target->id(),
30         'hook' => $this->pluginDefinition['hook'],
31       ]);
32       return;
33     }
34
35     foreach ($widgets as $id => $widget) {
36       $render = [
37         '#module' => $target->id(),
38         '#class' => $this->toTitleCase($id),
39         '#theme' => 'dmu_widget',
40         '#info' => [
41           'id' => $id,
42           'label' => $widget['label'],
43           'description' => $widget['description'] ?: NULL,
44           'field_types' => $widget['field types'],
45         ],
46       ];
47       $this->writeClass($target, $this->parse($render));
48     }
49   }
50
51 }