
| Current Path : /var/www/html/vendor/chi-teck/drupal-code-generator/templates/plugin/field/formatter/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/vendor/chi-teck/drupal-code-generator/templates/plugin/field/formatter/formatter.twig |
<?php
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
{% if configurable %}
use Drupal\Core\Form\FormStateInterface;
{% endif %}
/**
* Plugin implementation of the '{{ plugin_label }}' formatter.
*
* @FieldFormatter(
* id = "{{ plugin_id }}",
* label = @Translation("{{ plugin_label }}"),
* field_types = {
* "string"
* }
* )
*/
class {{ class }} extends FormatterBase {
{% if configurable %}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'foo' => 'bar',
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements['foo'] = [
'#type' => 'textfield',
'#title' => $this->t('Foo'),
'#default_value' => $this->getSetting('foo'),
];
return $elements;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary[] = $this->t('Foo: @foo', ['@foo' => $this->getSetting('foo')]);
return $summary;
}
{% endif %}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];
foreach ($items as $delta => $item) {
$element[$delta] = [
'#markup' => $item->value,
];
}
return $element;
}
}