public function JuiceboxFormatter::confBaseForm in Juicebox HTML5 Responsive Image Galleries 8.3
Same name and namespace in other branches
- 8.2 src/JuiceboxFormatter.php \Drupal\juicebox\JuiceboxFormatter::confBaseForm()
Get common elements for Juicebox configuration forms.
Several Juicebox gallery types can share common options and structures. These can be merged into the appropriate forms via a call to this method.
Parameters
array $form: The Drupal form array that common elements should be added to.
array $settings: An associative array containing all the current settings for a Juicebox gallery (used to set default values).
Return value
array The common form elements merged within a form array.
Overrides JuiceboxFormatterInterface::confBaseForm
File
- src/
JuiceboxFormatter.php, line 489
Class
- JuiceboxFormatter
- Class to define a Drupal service with common formatter methods.
Namespace
Drupal\juiceboxCode
public function confBaseForm(array $form, array $settings) {
// Get locally installed library details.
$library = $this
->getLibrary();
$disallowed_conf = [];
if (!empty($library) && empty($library['error'])) {
// If we don't have a known version of the Juicebox library, just show a
// generic warning.
if (empty($library['version'])) {
$notification_top = $this
->t('<strong>Notice:</strong> Your Juicebox Library version could not be detected. Some options below may not function correctly.');
}
elseif (!empty($library['disallowed_conf'])) {
$disallowed_conf = $library['disallowed_conf'];
$notification_top = $this
->t('<strong>Notice:</strong> You are currently using Juicebox library version <strong>@version</strong> which is not compatible with some of the options listed below. These options will appear disabled until you upgrade to the most recent Juicebox library version.', [
'@version' => $library['version'],
]);
$notification_label = $this
->t(' (not available in @version)', [
'@version' => $library['version'],
]);
}
}
else {
$notification_top = $this
->t('The Juicebox Javascript library does not appear to be installed. Please download and install the most recent version of the Juicebox library.');
$this->messenger
->addError($notification_top);
$form['#pre_render'] = [
static::class . '::preRenderFieldsets',
];
return $form;
}
$form['juicebox_config'] = [
'#type' => 'details',
'#title' => $this
->t('Juicebox Library - Lite Config'),
'#open' => FALSE,
'#description' => !empty($notification_top) ? '<p>' . $notification_top . '</p>' : '',
'#weight' => 10,
];
$form['jlib_galleryWidth'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'textfield',
'#title' => $this
->t('Gallery Width'),
'#description' => $this
->t('Set the gallery width in a standard numeric format (such as 100% or 300px).'),
'#element_validate' => [
'juicebox_element_validate_dimension',
],
];
$form['jlib_galleryHeight'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'textfield',
'#title' => $this
->t('Gallery Height'),
'#description' => $this
->t('Set the gallery height in a standard numeric format (such as 100% or 300px).'),
'#element_validate' => [
'juicebox_element_validate_dimension',
],
];
$form['jlib_backgroundColor'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'textfield',
'#title' => $this
->t('Background Color'),
'#description' => $this
->t('Set the gallery background color as a CSS3 color value (such as rgba(10,50,100,0.7) or #FF00FF).'),
];
$form['jlib_textColor'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'textfield',
'#title' => $this
->t('Text Color'),
'#description' => $this
->t('Set the color of all gallery text as a CSS3 color value (such as rgba(255,255,255,1) or #FF00FF).'),
];
$form['jlib_thumbFrameColor'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'textfield',
'#title' => $this
->t('Thumbnail Frame Color'),
'#description' => $this
->t('Set the color of the thumbnail frame as a CSS3 color value (such as rgba(255,255,255,.5) or #FF00FF).'),
];
$form['jlib_showOpenButton'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'checkbox',
'#title' => $this
->t('Show Open Image Button'),
'#description' => $this
->t('Whether to show the "Open Image" button. This will link to the full size version of the image within a new tab to facilitate downloading.'),
];
$form['jlib_showExpandButton'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'checkbox',
'#title' => $this
->t('Show Expand Button'),
'#description' => $this
->t('Whether to show the "Expand" button. Clicking this button expands the gallery to fill the browser window.'),
];
$form['jlib_useFullscreenExpand'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'checkbox',
'#title' => $this
->t('Use Fullscreen Expand'),
'#description' => $this
->t('Whether to trigger fullscreen mode when clicking the expand button (for supported browsers).'),
];
$form['jlib_showThumbsButton'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'checkbox',
'#title' => $this
->t('Show Thumbs Button'),
'#description' => $this
->t('Whether to show the "Toggle Thumbnails" button.'),
];
$form['jlib_useThumbDots'] = [
'#jb_fieldset' => 'juicebox_config',
'#type' => 'checkbox',
'#title' => $this
->t('Show Thumbs Dots'),
'#description' => $this
->t('Whether to replace the thumbnail images with small dots.'),
];
$form['juicebox_manual_config'] = [
'#type' => 'details',
'#title' => $this
->t('Juicebox Library - Pro / Manual Config'),
'#open' => FALSE,
'#description' => $this
->t('Specify any additional Juicebox library configuration options (such as "Pro" options) here.<br/>Options set here always take precedence over those set in the "Lite" options above if there is a conflict.'),
'#weight' => 20,
];
$form['manual_config'] = [
'#jb_fieldset' => 'juicebox_manual_config',
'#type' => 'textarea',
'#title' => $this
->t('Pro / Manual Configuraton Options'),
'#description' => $this
->t('Add one option per line in the format <strong>optionName="optionValue"</strong><br/>See also: http://www.juicebox.net/support/config_options'),
'#element_validate' => [
'juicebox_element_validate_config',
],
];
$form['advanced'] = [
'#type' => 'details',
'#title' => $this
->t('Juicebox - Advanced Options'),
'#open' => FALSE,
'#weight' => 30,
];
$form['incompatible_file_action'] = [
'#jb_fieldset' => 'advanced',
'#type' => 'select',
'#title' => $this
->t('Incompatible File Type Handling'),
'#options' => [
'skip' => $this
->t('Bypass incompatible files'),
'show_icon' => $this
->t('Show mimetype icon placehoder'),
'show_icon_and_link' => $this
->t('Show mimetype icon placholder and link to file'),
],
'#empty_option' => $this
->t('Do nothing'),
'#description' => $this
->t('Specify any special handling that should be applied to files that Juicebox cannot display (non-images).'),
];
$form['linkurl_source'] = [
'#jb_fieldset' => 'advanced',
'#type' => 'select',
'#title' => $this
->t("LinkURL Source"),
'#description' => $this
->t('The linkURL is an image-specific path for accessing each image outside the gallery. This is used by features such as the "Open Image Button".'),
'#options' => [
'image_styled' => 'Main Image - Styled (use this gallery\'s main image style setting)',
],
'#empty_option' => $this
->t('Main Image - Unstyled (original image)'),
];
$form['linkurl_target'] = [
'#jb_fieldset' => 'advanced',
'#type' => 'select',
'#title' => $this
->t('LinkURL Target'),
'#options' => [
'_blank' => $this
->t('_blank'),
'_self' => $this
->t('_self'),
'_parent' => $this
->t('_parent'),
'_top' => $this
->t('_top'),
],
'#description' => $this
->t('Specify a target for any links that make user of the image linkURL.'),
];
$form['custom_parent_classes'] = [
'#jb_fieldset' => 'advanced',
'#type' => 'textfield',
'#title' => $this
->t('Custom Classes for Parent Container'),
'#description' => $this
->t('Define any custom classes that should be added to the parent container within the Juicebox embed markup.<br/>This can be handy if you want to apply more advanced styling or dimensioning rules to this gallery via CSS. Enter as space-separated values.'),
];
// Set values that are directly related to each key.
foreach ($form as $conf_key => &$conf_value) {
if (!empty($conf_value['#type']) && $conf_value['#type'] != 'details') {
$conf_value['#default_value'] = $settings[$conf_key];
if (in_array($conf_key, $disallowed_conf)) {
$conf_value['#title'] .= $notification_label;
$conf_value['#disabled'] = TRUE;
}
}
}
// Add a pre render callback that will ensure that the items are nested
// correctly into fieldsets just before display.
$form['#pre_render'] = [
static::class . '::preRenderFieldsets',
];
return $form;
}