function ColorBackgroudFormatter::settingsForm
Same name in other branches
- 4.0.x modules/field_example/src/Plugin/Field/FieldFormatter/ColorBackgroudFormatter.php \Drupal\field_example\Plugin\Field\FieldFormatter\ColorBackgroudFormatter::settingsForm()
Define the Form API widgets a user should see when configuring the formatter. These are displayed when a user clicks the gear icon in the row for a formatter on the manage display page.
The field_ui module takes care of handling submitted form values.
Overrides FormatterBase::settingsForm
File
-
modules/
field_example/ src/ Plugin/ Field/ FieldFormatter/ ColorBackgroudFormatter.php, line 80
Class
- ColorBackgroudFormatter
- Plugin implementation of the 'field_example_color_background' formatter.
Namespace
Drupal\field_example\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
// Create a new array with one or more form elements. $form is available for
// context but you should not add your elements to it directly.
$elements = [];
// The keys of the array, 'adjust_text_color' in this case, should match
// what is defined in ::defaultSettings(), and the field_example.schema.yml
// schema. The values collected by the form will be automatically stored
// as part of the field instance configuration so you do not need to
// implement form submission processing.
$elements['adjust_text_color'] = [
'#type' => 'checkbox',
// The current configuration for this setting for the field instance can
// be accessed via $this->getSetting().
'#default_value' => $this->getSetting('adjust_text_color'),
'#title' => $this->t('Adjust foreground text color'),
'#description' => $this->t('Switch the foreground color between black and white depending on lightness of the background color.'),
];
return $elements;
}