HookFieldFormatterInfo.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/HookFieldFormatterInfo.php
View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
use Drupal\drupalmoduleupgrader\ConverterBase;
use Drupal\drupalmoduleupgrader\TargetInterface;
use Drupal\drupalmoduleupgrader\Utility\StringTransformTrait;
class HookFieldFormatterInfo extends ConverterBase {
use StringTransformTrait;
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));
}
}
}
Classes
Name |
Description |
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"
) |