public function BlazyFilter::settingsForm in Blazy 8.2
Same name and namespace in other branches
- 7 src/Plugin/Filter/BlazyFilter.php \Drupal\blazy\Plugin\Filter\BlazyFilter::settingsForm()
Generates a filter's settings form.
Parameters
array $form: A minimally prepopulated form array.
\Drupal\Core\Form\FormStateInterface $form_state: The state of the (entire) configuration form.
Return value
array The $form array with additional form elements for the settings of this filter. The submitted form values should match $this->settings.
Overrides FilterBase::settingsForm
File
- src/
Plugin/ Filter/ BlazyFilter.php, line 536
Class
- BlazyFilter
- Provides a filter to lazyload image, or iframe elements.
Namespace
Drupal\blazy\Plugin\FilterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$lightboxes = $this->blazyManager
->getLightboxes();
$form['filter_tags'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Enable HTML tags'),
'#options' => [
'img' => $this
->t('Image'),
'iframe' => $this
->t('Video iframe'),
],
'#default_value' => empty($this->settings['filter_tags']) ? [] : array_values((array) $this->settings['filter_tags']),
'#description' => $this
->t('Recommended placement after Align / Caption images. To disable Blazy per individual item, add attribute <code>data-unblazy</code>.'),
'#prefix' => '<p>' . $this
->t('<b>Warning!</b> Blazy Filter is useless and broken when you enable <b>Media embed</b> or <b>Display embedded entities</b>. You can disable Blazy Filter in favor of Blazy formatter embedded inside <b>Media embed</b> or <b>Display embedded entities</b> instead. However it might be useful for User Generated Contents (UGC) where Entity/Media Embed are likely more for privileged users, authors, editors, admins, alike. Or when Entity/Media Embed is disabled. Or when editors prefer pasting embed codes from video providers rather than creating media entities.') . '</p>',
];
$form['media_switch'] = [
'#type' => 'select',
'#title' => $this
->t('Media switcher'),
'#options' => [
'media' => $this
->t('Image to iframe'),
],
'#empty_option' => $this
->t('- None -'),
'#default_value' => isset($this->settings['media_switch']) ? $this->settings['media_switch'] : '',
'#description' => $this
->t('<ul><li><b>Image to iframe</b> will play video when toggled.</li><li><b>Image to lightbox</b> (Colorbox, Photobox, PhotoSwipe, Slick Lightbox, Zooming, Intense, etc.) will display media in lightbox.</li></ul>Both can stand alone or grouped as a gallery. To build a gallery, add <code>data-column="1 3 4"</code> or <code>data-grid="1 3 4"</code> to the first image/ iframe only.'),
];
if (!empty($lightboxes)) {
foreach ($lightboxes as $lightbox) {
$name = Unicode::ucwords(str_replace('_', ' ', $lightbox));
$form['media_switch']['#options'][$lightbox] = $this
->t('Image to @lightbox', [
'@lightbox' => $name,
]);
}
}
$styles = $this->blazyAdmin
->getResponsiveImageOptions() + $this->blazyAdmin
->getEntityAsOptions('image_style');
$form['hybrid_style'] = [
'#type' => 'select',
'#title' => $this
->t('(Responsive) image style'),
'#options' => $styles,
'#empty_option' => $this
->t('- None -'),
'#default_value' => isset($this->settings['hybrid_style']) ? $this->settings['hybrid_style'] : '',
'#description' => $this
->t('Fallback (Responsive) image style when <code>[data-image-style]</code> or <code>[data-responsive-image-style]</code> attributes are not present, see https://drupal.org/node/2061377.'),
];
$form['box_style'] = [
'#type' => 'select',
'#title' => $this
->t('Lightbox (Responsive) image style'),
'#options' => $styles,
'#empty_option' => $this
->t('- None -'),
'#default_value' => isset($this->settings['box_style']) ? $this->settings['box_style'] : '',
];
$captions = $this->blazyAdmin
->getLightboxCaptionOptions();
unset($captions['entity_title'], $captions['custom']);
$form['box_caption'] = [
'#type' => 'select',
'#title' => $this
->t('Lightbox caption'),
'#options' => $captions + [
'inline' => $this
->t('Caption filter'),
],
'#empty_option' => $this
->t('- None -'),
'#default_value' => isset($this->settings['box_caption']) ? $this->settings['box_caption'] : '',
'#description' => $this
->t('Automatic will search for Alt text first, then Title text. <br>Image styles only work for uploaded images, not hand-coded ones.'),
];
$form['use_data_uri'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Trust data URI'),
'#default_value' => isset($this->settings['use_data_uri']) ? $this->settings['use_data_uri'] : FALSE,
'#description' => $this
->t('Enable to support the use of data URI. Leave it unchecked if unsure, or never use data URI.'),
];
return $form;
}