public function GalleryFormatterFormatter::settingsForm in Gallery 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 ResponsiveImageFormatter::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ GalleryFormatterFormatter.php, line 38
Class
- GalleryFormatterFormatter
- Plugin for galleryformatter.
Namespace
Drupal\galleryformatter\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$responsive_image_styles = $this->responsiveImageStyleStorage
->loadMultiple();
$elements = [];
// get a list of all style names for our elements options
foreach ($responsive_image_styles as $id => $style) {
$options[$id] = $id;
}
$elements['slide_style'] = [
'#type' => 'select',
'#title' => $this
->t('Select the slide style'),
'#options' => $options,
'#default_value' => $this
->getSetting('slide_style'),
'#description' => $this
->t('Select the imagecache style you would like to show when clicked on the thumbnail.'),
];
$elements['thumb_style'] = [
'#type' => 'select',
'#title' => $this
->t('Select the thumbnail style'),
'#options' => $options,
'#default_value' => $this
->getSetting('thumb_style'),
'#description' => $this
->t('Select the imagecache style you would like to show for the thumbnails list.'),
];
$style_options = [
'@todo',
];
// @TODO Implement a plugin type instead of defining a new hook.
$styles = [];
// $styles = \Drupal::moduleHandler()->invokeAll('galleryformatter_styles');
// The keys used for options must be valid html id-s.
foreach ($styles as $style) {
$style_options[$style] = $style;
}
ksort($style_options);
$elements['style'] = [
'#type' => 'select',
'#title' => $this
->t('Style'),
'#options' => [
'nostyle' => $this
->t('No style'),
] + $style_options,
'#default_value' => $this
->getSetting('style'),
'#description' => $this
->t('Choose the gallery style.'),
];
$modal_options = [];
// integration with other modules for jQuery modal windows
if (\Drupal::moduleHandler()
->moduleExists('colorbox')) {
$modal_options['colorbox'] = 'colorbox';
}
if (\Drupal::moduleHandler()
->moduleExists('shadowbox')) {
$modal_options['shadowbox'] = 'shadowbox';
}
if (\Drupal::moduleHandler()
->moduleExists('lightbox2')) {
$modal_options['lightbox2'] = 'lightbox2';
}
if (\Drupal::moduleHandler()
->moduleExists('fancybox')) {
$modal_options['fancybox'] = 'fancybox';
}
$modal_options['none'] = t('Do not use modal');
$elements['modal'] = [
'#type' => 'select',
'#title' => $this
->t('Use jQuery modal for full image link'),
'#options' => $modal_options,
'#default_value' => $this
->getSetting('modal'),
'#description' => $this
->t("Select which jQuery modal module you'd like to display the full link image in, if any."),
];
return $elements;
}