function ResponsiveImageFormatter::settingsForm
Same name in other branches
- 9 core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php \Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter::settingsForm()
- 8.9.x core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php \Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter::settingsForm()
- 11.x core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php \Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter::settingsForm()
Overrides FormatterBase::settingsForm
File
-
core/
modules/ responsive_image/ src/ Plugin/ Field/ FieldFormatter/ ResponsiveImageFormatter.php, line 128
Class
- ResponsiveImageFormatter
- Plugin for responsive image formatter.
Namespace
Drupal\responsive_image\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$responsive_image_options = [];
$responsive_image_styles = $this->responsiveImageStyleStorage
->loadMultiple();
uasort($responsive_image_styles, '\\Drupal\\responsive_image\\Entity\\ResponsiveImageStyle::sort');
if ($responsive_image_styles && !empty($responsive_image_styles)) {
foreach ($responsive_image_styles as $machine_name => $responsive_image_style) {
if ($responsive_image_style->hasImageStyleMappings()) {
$responsive_image_options[$machine_name] = $responsive_image_style->label();
}
}
}
$elements['responsive_image_style'] = [
'#title' => $this->t('Responsive image style'),
'#type' => 'select',
'#default_value' => $this->getSetting('responsive_image_style') ?: NULL,
'#required' => TRUE,
'#options' => $responsive_image_options,
'#description' => [
'#markup' => $this->linkGenerator
->generate($this->t('Configure Responsive Image Styles'), new Url('entity.responsive_image_style.collection')),
'#access' => $this->currentUser
->hasPermission('administer responsive image styles'),
],
];
$image_loading = $this->getSetting('image_loading');
$elements['image_loading'] = [
'#type' => 'details',
'#title' => $this->t('Image loading'),
'#weight' => 10,
'#description' => $this->t('Lazy render images with native image loading attribute (<em>loading="lazy"</em>). This improves performance by allowing browsers to lazily load images. See <a href="@url">Lazy loading</a>.', [
'@url' => 'https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading#images_and_iframes',
]),
];
$loading_attribute_options = [
'lazy' => $this->t('Lazy'),
'eager' => $this->t('Eager'),
];
$elements['image_loading']['attribute'] = [
'#title' => $this->t('Lazy loading attribute'),
'#type' => 'select',
'#default_value' => $image_loading['attribute'],
'#options' => $loading_attribute_options,
'#description' => $this->t('Select the lazy loading attribute for images. <a href=":link">Learn more.</a>', [
':link' => 'https://html.spec.whatwg.org/multipage/urls-and-fetching.html#lazy-loading-attributes',
]),
];
$link_types = [
'content' => $this->t('Content'),
'file' => $this->t('File'),
];
$elements['image_link'] = [
'#title' => $this->t('Link image to'),
'#type' => 'select',
'#default_value' => $this->getSetting('image_link'),
'#empty_option' => $this->t('Nothing'),
'#options' => $link_types,
];
return $elements;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.