Skip to content
Snippets Groups Projects
Commit 2df1d82e authored by Shelane French's avatar Shelane French
Browse files

Issue #3450656: Create update hook that will account for most new options

parent 4c815caa
No related branches found
No related tags found
1 merge request!25Resolve #3450656 "Create update hook"
Pipeline #185316 passed with warnings
<?php
/**
* @file
* Contains update functions for Views Bootstrap.
*/
/**
* Update Views Bootstrap style configuration for Bootstrap 5 options.
*/
function views_bootstrap_update_91001(&$sandbox) {
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('views.view.') as $view_config_name) {
$view = $config_factory->getEditable($view_config_name);
$save = FALSE;
$displays = $view->get('display');
foreach ($displays as $display_name => &$display) {
if (!empty($display['display_options']['style']) && !empty($display['display_options']['style']['options'])) {
$style = (string) $display['display_options']['style']['type'];
$options = $display['display_options']['style']['options'];
// Check cards for set columns value.
if ($style == 'views_bootstrap_cards' && !array_key_exists('columns', $options)) {
$display['display_options']['style']['options']['columns'] = 1;
\Drupal::logger('views_bootstrap')->notice("Updating cards column to default in $display_name for $view_config_name");
$save = TRUE;
}
// Check carousel for new options.
if ($style == 'views_bootstrap_carousel' && !array_key_exists('keyboard', $options)) {
$display['display_options']['style']['options']['keyboard'] = TRUE;
$display['display_options']['style']['options']['ride'] = TRUE;
$display['display_options']['style']['options']['use_caption'] = TRUE;
$display['display_options']['style']['options']['effect'] = 'slide';
\Drupal::logger('views_bootstrap')->notice("Updating options in $display_name for $view_config_name");
$save = TRUE;
}
// Check media object for image placement.
if ($style == 'views_bootstrap_media_object' && !array_key_exists('image_placement', $options)) {
$display['display_options']['style']['options']['image_placement'] = 'first';
\Drupal::logger('views_bootstrap')->notice("Updating image placement in $display_name for $view_config_name");
$save = TRUE;
}
}
}
if ($save) {
$view->set('display', $displays);
$view->save(TRUE);
}
}
}
......@@ -361,16 +361,16 @@ function template_preprocess_views_bootstrap_tab(array &$vars): void {
* - rows: The raw row data.
*/
function template_preprocess_views_bootstrap_table(array &$vars): void {
$view = $vars['view'];
$option_classes = array_filter(explode(' ', $view->style_plugin->options['table_class_custom']));
$classes = array_map([Html::class, 'cleanCssIdentifier'], $option_classes);
$vars['responsive'] = $view->style_plugin->options['responsive'];
$vars['attributes']['class'][] = 'table';
foreach (array_filter($vars['view']->style_plugin->options['bootstrap_styles']) as $style) {
$vars['attributes']['class'][] = 'table-' . $style;
$options = $vars['view']->style_plugin->options;
$vars['attributes'] = new Attribute(['class' => 'table']);
$vars['responsive'] = $options['responsive'];
foreach (array_filter($options['bootstrap_styles']) as $style) {
$vars['attributes']->addClass('table-' . $style);
}
if (!empty($classes)) {
$vars['attributes']['class'] = array_merge($vars['attributes']['class'], $classes);
if ($options['table_class_custom']) {
$option_classes = array_filter(explode(' ', $options['table_class_custom']));
$classes = array_map([Html::class, 'cleanCssIdentifier'], $option_classes);
$vars['attributes']->addClass($classes);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment