TestFieldMultipleFormatter.php in Zircon Profile 8.0
File
core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.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 TestFieldMultipleFormatter extends FormatterBase {
public static function defaultSettings() {
return array(
'test_formatter_setting_multiple' => 'dummy test string',
'alter' => FALSE,
) + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['test_formatter_setting_multiple'] = array(
'#title' => t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $this
->getSetting('test_formatter_setting_multiple'),
'#required' => TRUE,
);
return $element;
}
public function settingsSummary() {
$summary = array();
$summary[] = t('@setting: @value', array(
'@setting' => 'test_formatter_setting_multiple',
'@value' => $this
->getSetting('test_formatter_setting_multiple'),
));
return $summary;
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
if (!empty($items)) {
$array = array();
foreach ($items as $delta => $item) {
$array[] = $delta . ':' . $item->value;
}
$elements[0] = array(
'#markup' => $this
->getSetting('test_formatter_setting_multiple') . '|' . implode('|', $array),
);
}
return $elements;
}
}