You are here

public function HookFieldFormatterInfo::convert in Drupal 7 to 8/9 Module Upgrader 8

Performs required conversions.

Parameters

TargetInterface $target: The target module to convert.

Overrides ConverterInterface::convert

File

src/Plugin/DMU/Converter/HookFieldFormatterInfo.php, line 23

Class

HookFieldFormatterInfo
Plugin annotation @Converter( id = "hook_field_formatter_info", description = @Translation("Creates formatter class templates from hook_field_formatter_info()."), hook = "hook_field_formatter_info" )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter

Code

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));
  }
}