public function BgImgFieldFormatter::settingsForm in Background Image Field 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 ResponsiveImageFormatter::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ BgImgFieldFormatter.php, line 112
Class
- BgImgFieldFormatter
- Plugin implementation of the 'image' formatter.
Namespace
Drupal\bg_img_field\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
// Get the options for responsive image styles.
$options = $elements['responsive_image_style']['#options'];
// New options array for storing new option values.
$new_options = [];
// Loop through the options to locate only the ones that are labeled
// image styles. This will eliminate any by size styles.
foreach ($options as $key => $option) {
$storage = $this->responsiveImageStyleStorage
->load($key);
$image_style_mappings = $storage
->get('image_style_mappings');
if (isset($image_style_mappings[0]) && $image_style_mappings[0]['image_mapping_type'] === 'image_style') {
$new_options += [
$key => $option,
];
}
}
$elements['responsive_image_style']['#options'] = $new_options;
// Remove the image link element.
unset($elements['image_link']);
return $elements;
}