function hook_slick_optionset_alter in Slick Carousel 8
Same name and namespace in other branches
- 8.2 slick.api.php \hook_slick_optionset_alter()
- 7.3 slick.api.php \hook_slick_optionset_alter()
Modifies Slick optionset before being passed to preprocess, or templates.
Parameters
\Drupal\slick\Entity\Slick $slick: The Slick object being modified.
array $settings: The contextual settings related to UI and HTML layout settings.
See also
\Drupal\slick\SlickManager::preRenderSlick()
Related topics
1 invocation of hook_slick_optionset_alter()
- SlickManager::preRenderSlick in src/
SlickManager.php - Builds the Slick instance as a structured array ready for ::renderer().
File
- ./
slick.api.php, line 525 - Hooks and API provided by the Slick module.
Code
function hook_slick_optionset_alter(Slick &$slick, array $settings) {
if ($slick
->id() == 'x_slick_nav') {
// Overrides the main settings of navigation with optionset ID x_slick_nav.
// To see available options, see config/install/slick.optionset.default.yml.
// Disable arrows.
$slick
->setSetting('arrows', FALSE);
// Checks if we have defined responsive settings.
if ($responsives = $slick
->getResponsiveOptions()) {
foreach ($responsives as $key => $responsive) {
if ($responsive['breakpoint'] == 481) {
// If Optimized option is enabled, only those different from default
// settings will be displayed at $responsive array. To poke around
// available settings, see config/install/slick.optionset.default.yml
// See what we have here.
// dpr($responsive);
// Overrides responsive settings.
$values = $responsive['settings'];
$values['centerPadding'] = '40px';
$values['slidesToShow'] = 1;
// Assign the new settings values.
$slick
->setResponsiveSettings($values, $key);
// Verify responsive settings updated.
// dpr($slick->getResponsiveOptions());
}
}
}
}
}