class TestFieldMultipleFormatter
Same name in other branches
- 9 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldMultipleFormatter
- 8.9.x core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldMultipleFormatter
- 10 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldMultipleFormatter
Plugin implementation of the 'field_test_multiple' formatter.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Field\PluginSettingsBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface
- class \Drupal\Core\Field\FormatterBase extends \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldMultipleFormatter extends \Drupal\Core\Field\FormatterBase
- class \Drupal\Core\Field\FormatterBase extends \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Field\PluginSettingsBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of TestFieldMultipleFormatter
File
-
core/
modules/ field/ tests/ modules/ field_test/ src/ Plugin/ Field/ FieldFormatter/ TestFieldMultipleFormatter.php, line 16
Namespace
Drupal\field_test\Plugin\Field\FieldFormatterView source
class TestFieldMultipleFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'test_formatter_setting_multiple' => 'dummy test string',
'alter' => FALSE,
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['test_formatter_setting_multiple'] = [
'#title' => $this->t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $this->getSetting('test_formatter_setting_multiple'),
'#required' => TRUE,
];
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
$summary[] = $this->t('@setting: @value', [
'@setting' => 'test_formatter_setting_multiple',
'@value' => $this->getSetting('test_formatter_setting_multiple'),
]);
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
if (!empty($items)) {
$array = [];
foreach ($items as $delta => $item) {
$array[] = $delta . ':' . $item->value;
}
$elements[0] = [
'#markup' => $this->getSetting('test_formatter_setting_multiple') . '|' . implode('|', $array),
];
}
return $elements;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.