TestFieldDefaultFormatter.php in Zircon Profile 8.0
File
core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php
View source
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
class TestFieldDefaultFormatter extends FormatterBase {
public static function defaultSettings() {
return array(
'test_formatter_setting' => 'dummy test string',
) + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['test_formatter_setting'] = array(
'#title' => t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $this
->getSetting('test_formatter_setting'),
'#required' => TRUE,
);
return $element;
}
public function settingsSummary() {
$summary = array();
$summary[] = t('@setting: @value', array(
'@setting' => 'test_formatter_setting',
'@value' => $this
->getSetting('test_formatter_setting'),
));
return $summary;
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#markup' => $this
->getSetting('test_formatter_setting') . '|' . $item->value,
);
}
return $elements;
}
}