protected function JuiceboxFormatter::setGalleryOptions in Juicebox HTML5 Responsive Image Galleries 8.2
Same name and namespace in other branches
- 8.3 src/JuiceboxFormatter.php \Drupal\juicebox\JuiceboxFormatter::setGalleryOptions()
Utility to extract Juicebox options from common Drupal display settings.
And add them to the gallery.
Some common Juicebox configuration options are set via a GUI and others are set as manual strings. This method fetches all of these values from drupal settings data and merges them into the gallery. Note that this only accounts for common settings.
Parameters
Drupal\juicebox\JuiceboxGalleryInterface $gallery: An initialized Juicebox gallery object.
array $settings: An associative array of gallery-specific settings.
1 call to JuiceboxFormatter::setGalleryOptions()
- JuiceboxFormatter::runCommonBuild in src/
JuiceboxFormatter.php - Common post-build task.
File
- src/
JuiceboxFormatter.php, line 363
Class
- JuiceboxFormatter
- Class to define a Drupal service with common formatter methods.
Namespace
Drupal\juiceboxCode
protected function setGalleryOptions(JuiceboxGalleryInterface $gallery, array $settings) {
// Get the string options set via the GUI.
foreach ([
'jlib_galleryWidth',
'jlib_galleryHeight',
'jlib_backgroundColor',
'jlib_textColor',
'jlib_thumbFrameColor',
] as $name) {
if (isset($settings[$name])) {
$name_real = str_replace('jlib_', '', $name);
$gallery
->addOption(Unicode::strtolower($name_real), trim(Html::escape($settings[$name])));
}
}
// Get the bool options set via the GUI.
foreach ([
'jlib_showOpenButton',
'jlib_showExpandButton',
'jlib_showThumbsButton',
'jlib_useThumbDots',
'jlib_useFullscreenExpand',
] as $name) {
if (isset($settings[$name])) {
$name_real = str_replace('jlib_', '', $name);
$gallery
->addOption(Unicode::strtolower($name_real), !empty($settings[$name]) ? 'TRUE' : 'FALSE');
}
}
// Merge-in the manually assigned options making sure they take priority
// over any conflicting GUI options.
if (!empty($settings['manual_config'])) {
$manual_options = explode("\n", $settings['manual_config']);
foreach ($manual_options as $option) {
$option = trim($option);
if (!empty($option)) {
// Each manual option has only been validated (on input) to be in the
// form optionName="optionValue". Now we need split and sanitize the
// values.
$matches = [];
preg_match('/^([A-Za-z0-9]+?)="([^"]+?)"$/u', $option, $matches);
list($full_match, $name, $value) = $matches;
$gallery
->addOption(Unicode::strtolower($name), Html::escape($value));
}
}
}
}