public function BackgroundImageFormatter::settingsForm in Simple Background image formatter 8
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides ImageFormatter::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ BackgroundImageFormatter.php, line 36
Class
- BackgroundImageFormatter
- Plugin implementation of the background_image_formatter.
Namespace
Drupal\background_image_formatter\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$image_styles = image_style_options(FALSE);
$element['image_style'] = [
'#title' => $this
->t('Image style'),
'#type' => 'select',
'#options' => $image_styles,
'#default_value' => $this
->getSetting('image_style'),
'#empty_option' => $this
->t('None (original image)'),
'#description' => $this
->t('Select the image style to use.'),
];
$element['background_image_output_type'] = [
'#title' => $this
->t('Output To'),
'#type' => 'select',
'#options' => [
'inline' => $this
->t('Write background-image to inline style attribute'),
'css' => $this
->t('Write background-image to CSS selector'),
],
'#default_value' => $this
->getSetting('background_image_output_type'),
'#required' => TRUE,
'#description' => $this
->t('Define how background-image will be printed to the dom.'),
];
$element['background_image_selector'] = [
'#title' => $this
->t('CSS Selector'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('background_image_selector'),
'#required' => FALSE,
'#description' => $this
->t('CSS selector that image(s) are attached to.'),
];
return $element;
}