public function JuiceboxFieldFormatter::settingsForm in Juicebox HTML5 Responsive Image Galleries 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/Field/FieldFormatter/JuiceboxFieldFormatter.php \Drupal\juicebox\Plugin\Field\FieldFormatter\JuiceboxFieldFormatter::settingsForm()
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 FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ JuiceboxFieldFormatter.php, line 112
Class
- JuiceboxFieldFormatter
- Plugin implementation of the 'juicebox' formatter.
Namespace
Drupal\juicebox\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
// Detect if this is a "pseudo" instance such that the field's context is
// managed by something other than the core Field API (e.g., a fake instance
// used for a a view row). This case is supported but we still want to put
// up a notice about it.
if ($this
->isPseudoInstance()) {
$element['instance_warning'] = [
'#prefix' => '<div class="messages messages--warning">',
'#markup' => $this
->t('<strong>WARNING:</strong> You appear to be using the Juicebox field formatter with a field instance that is not directly attached to an entity. Support for this configuration is currently experimental. Please test your final gallery output thoroughly.'),
'#suffix' => '</div>',
];
}
// Get available title and caption sources.
$text_sources = $this
->getFieldTextSources();
// Add the field-formatter-specific elements.
$element['image_style'] = [
'#type' => 'select',
'#title' => $this
->t('Main Image Style'),
'#default_value' => $this
->getSetting('image_style'),
'#description' => $this
->t('The style formatter for the main image.'),
'#options' => $this->juicebox
->confBaseStylePresets(),
'#empty_option' => $this
->t('None (original image)'),
];
$element['thumb_style'] = [
'#type' => 'select',
'#title' => $this
->t('Thumbnail Style'),
'#default_value' => $this
->getSetting('thumb_style'),
'#description' => $this
->t('The style formatter for the thumbnail.'),
'#options' => $this->juicebox
->confBaseStylePresets(FALSE),
'#empty_option' => $this
->t('None (original image)'),
];
$element['caption_source'] = [
'#type' => 'select',
'#title' => $this
->t('Caption Source'),
'#default_value' => $this
->getSetting('caption_source'),
'#description' => $this
->t('The image value that should be used for the caption.'),
'#options' => $text_sources,
'#empty_option' => $this
->t('No caption'),
];
$element['title_source'] = [
'#type' => 'select',
'#title' => $this
->t('Title Source'),
'#default_value' => $this
->getSetting('title_source'),
'#description' => $this
->t('The image value that should be used for the title.'),
'#options' => $text_sources,
'#empty_option' => $this
->t('No title'),
];
// Add the common configuration options.
$element = $this->juicebox
->confBaseForm($element, $this
->getSettings());
return $element;
}