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.
*/
class {{ class }} extends FormatterBase {
+{% if configurable %}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
- 'prefix' => '',
- 'suffix' => '',
+ 'foo' => 'bar',
] + parent::defaultSettings();
}
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
- $settings = $this->getSettings();
- $elements['prefix'] = [
+ $elements['foo'] = [
'#type' => 'textfield',
- '#title' => $this->t('Prefix'),
- '#default_value' => $settings['prefix'],
- ];
-
- $elements['suffix'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Suffix'),
- '#default_value' => $settings['suffix'],
+ '#title' => $this->t('Foo'),
+ '#default_value' => $this->getSetting('foo'),
];
return $elements;
* {@inheritdoc}
*/
public function settingsSummary() {
- $settings = $this->getSettings();
- $summary = [];
-
- if ($settings['prefix']) {
- $summary[] = $this->t('Prefix: @prefix', ['@prefix' => $settings['prefix']]);
- }
- if ($settings['suffix']) {
- $summary[] = $this->t('Suffix: @suffix', ['@suffix' => $settings['suffix']]);
- }
-
+ $summary[] = $this->t('Foo: @foo', ['@foo' => $this->getSetting('foo')]);
return $summary;
}
+{% endif %}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];
- $settings = $this->getSettings();
foreach ($items as $delta => $item) {
$element[$delta] = [
'#type' => 'item',
'#markup' => $item->value,
- '#field_prefix' => $settings['prefix'],
- '#field_suffix' => $settings['suffix'],
];
}