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

Issue #3447167 by shelane: Validate each component for Bootstrap 5

parent 859feb36
No related branches found
No related tags found
1 merge request!18updates accordion
Pipeline #173782 passed with warnings
Showing
with 341 additions and 124 deletions
......@@ -3,21 +3,24 @@ views.style.views_bootstrap_accordion:
label: 'Views bootstrap accordion'
mapping:
panel_title_field:
type: label
label: "Panel title field"
collapse:
type: mapping
label: "Collapse"
mapping:
first:
type: string
label: "First"
middle:
label: "Panel title field"
flush:
type: boolean
label: "Flush Borders"
behavior:
type: string
label: "Middle"
last:
label: "Collapse Options"
options:
closed: "All Items Closed"
all: "All Items Open"
specify: "Specify Behavior by Section"
sections:
type: array
label: "Open Elements"
items:
type: string
label: "Last"
default: []
views.style.views_bootstrap_cards:
type: views_style
......@@ -32,6 +35,15 @@ views.style.views_bootstrap_cards:
card_image_field:
type: label
label: "Card image field"
card_group_class_custom:
type: label
label: "Card group class custom"
card_class_custom:
type: label
label: "Card class custom"
columns:
type: label
label: "Maximum cards per row"
views.style.views_bootstrap_carousel:
type: views_style
......
......@@ -40,9 +40,10 @@ class ViewsBootstrapAccordion extends StylePluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['panel_title_field'] = ['default' => ''];
$options['collapse']['first'] = ['default' => 0];
$options['collapse']['middle'] = ['default' => 0];
$options['collapse']['last'] = ['default' => 0];
$options['label_field'] = ['default' => NULL];
$options['flush'] = ['default' => FALSE];
$options['behavior'] = ['default' => 'closed'];
$options['sections'] = ['default' => NULL];
return $options;
}
......@@ -52,9 +53,11 @@ class ViewsBootstrapAccordion extends StylePluginBase {
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
if (isset($form['grouping'])) {
unset($form['grouping']);
$form['help'] = [
'#markup' => $this->t('The Bootstrap accordion displays content in collapsible panels (<a href=":docs">see documentation</a>).', [':docs' => 'https://www.drupal.org/docs/contributed-modules/views-bootstrap-for-bootstrap-3/accordion']),
'#weight' => -99,
];
$form['panel_title_field'] = [
'#type' => 'select',
'#title' => $this->t('Panel title field'),
......@@ -63,35 +66,39 @@ class ViewsBootstrapAccordion extends StylePluginBase {
'#default_value' => $this->options['panel_title_field'],
'#description' => $this->t('Select the field that will be used as the accordion panel titles.'),
];
}
$options_select = [
0 => $this->t('Collapsed'),
1 => $this->t('Uncollapsed'),
];
$form['collapse'] = [
'#type' => 'fieldset',
'#title' => $this->t('Collapse options'),
];
$form['collapse']['first'] = [
'#type' => 'select',
'#title' => $this->t('First element'),
'#options' => $options_select,
'#default_value' => $this->options['collapse']['first'],
'#description' => $this->t('To collapse/uncollapse the first element of the list. If there is only one item, first element settings prevails than the others (middle, last)'),
$form['flush'] = [
'#type' => 'checkbox',
'#title' => $this->t('Flush Borders'),
'#description' => $this->t('Add accordion-flush class to remove some borders and rounded corners to render accordions edge-to-edge with their parent container.'),
'#default_value' => $this->options['flush'],
];
$form['collapse']['middle'] = [
'#type' => 'select',
'#title' => $this->t('Middle elements'),
'#options' => $options_select,
'#default_value' => $this->options['collapse']['middle'],
'#description' => $this->t('To collapse/uncollapse the middle elements of the list.'),
$form['behavior'] = [
'#type' => 'radios',
'#title' => $this->t('Collapse Options'),
'#options' => [
'closed' => $this->t('All Items Closed'),
'all' => $this->t('All Items Open'),
'specify' => $this->t('Specify Behavior by Section'),
],
'#required' => TRUE,
'#description' => $this->t('Default panel state for collapse behavior.'),
'#default_value' => $this->options['behavior'],
];
$form['collapse']['last'] = [
'#type' => 'select',
'#title' => $this->t('Last element'),
'#options' => $options_select,
'#default_value' => $this->options['collapse']['last'],
'#description' => $this->t('To collapse/uncollapse the last element of the list.'),
$form['sections'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Open Elements'),
'#options' => [
'first' => $this->t('First'),
'middle' => $this->t('Middle'),
'last' => $this->t('Last'),
],
'#description' => $this->t('Select the elements which will be opened.'),
'#states' => [
'visible' => [
':input[name="style_options[behavior]"]' => ['value' => 'specify'],
],
],
'#default_value' => $this->options['sections'],
];
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\views_bootstrap\Plugin\views\style;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
......@@ -34,15 +35,45 @@ class ViewsBootstrapCards extends StylePluginBase {
*/
protected $usesRowPlugin = TRUE;
/**
* Return the token-replaced row or column classes for the specified result.
*
* @param int $result_index
* The delta of the result item to get custom classes for.
* @param string $type
* The type of custom grid class to return, either "card_group" or "card".
*
* @return string
* A space-delimited string of classes.
*/
public function getCustomClass(int $result_index, $type): string {
if (isset($this->options[$type . '_class_custom'])) {
$class = $this->options[$type . '_class_custom'];
if ($this->usesFields() && $this->view->field) {
$class = strip_tags($this->tokenizeValue($class, $result_index));
}
$classes = explode(' ', $class);
foreach ($classes as &$class) {
$class = Html::cleanCssIdentifier($class);
}
return implode(' ', $classes);
}
return '';
}
/**
* Definition.
*/
protected function defineOptions() {
$options = parent::defineOptions();
unset($options['grouping']);
$options['card_title_field'] = ['default' => ''];
$options['card_content_field'] = ['default' => ''];
$options['card_image_field'] = ['default' => ''];
$options['card_title_field'] = ['default' => NULL];
$options['card_content_field'] = ['default' => NULL];
$options['card_image_field'] = ['default' => NULL];
$options['card_group_class_custom'] = ['default' => NULL];
$options['card_class_custom'] = ['default' => NULL];
$options['columns'] = ['default' => NULL];
return $options;
}
......@@ -76,6 +107,38 @@ class ViewsBootstrapCards extends StylePluginBase {
'#default_value' => $this->options['card_image_field'],
'#description' => $this->t('Select the field that will be used for the card image.'),
];
$form['card_group_class_custom'] = [
'#title' => $this->t('Custom card group class'),
'#description' => $this->t('Additional classes to provide on the card group. Separated by a space.'),
'#type' => 'textfield',
'#default_value' => $this->options['card_group_class_custom'],
];
$form['card_class_custom'] = [
'#title' => $this->t('Custom card class'),
'#description' => $this->t('Additional classes to provide on each card. Separated by a space.'),
'#type' => 'textfield',
'#default_value' => $this->options['card_class_custom'],
];
$form['columns'] = [
'#type' => 'select',
'#title' => $this->t('Maximum cards per row'),
'#description' => $this->t('The number of cards to include in a row.'),
'#options' => [
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
],
'#default_value' => $this->options['columns'],
];
}
}
......@@ -54,6 +54,11 @@ class ViewsBootstrapGrid extends StylePluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['help'] = [
'#markup' => $this->t('The Bootstrap grid displays content in a responsive, mobile first fluid grid (<a href=":docs">see documentation</a>).', [':docs' => 'https://www.drupal.org/docs/contributed-modules/views-bootstrap-for-bootstrap-3/grid']),
'#weight' => -99,
];
foreach (ViewsBootstrap::getBreakpoints() as $breakpoint) {
$breakpoint_option = "col_$breakpoint";
$prefix = 'col' . ($breakpoint != 'xs' ? '-' . $breakpoint : '');
......
......@@ -40,6 +40,7 @@ class ViewsBootstrapListGroup extends StylePluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['list_group_class_custom'] = ['default' => NULL];
$options['title_field'] = ['default' => ''];
return $options;
}
......@@ -50,6 +51,18 @@ class ViewsBootstrapListGroup extends StylePluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['help'] = [
'#markup' => $this->t('The Bootstrap list group displays content in an unordered list with list group classes (<a href=":docs">see documentation</a>).', [':docs' => 'https://www.drupal.org/docs/contributed-modules/views-bootstrap-for-bootstrap-3/list-group']),
'#weight' => -99,
];
$form['list_group_class_custom'] = [
'#title' => $this->t('Custom list group class'),
'#description' => $this->t('Additional classes to provide on the list group. Separated by a space.'),
'#type' => 'textfield',
'#default_value' => $this->options['list_group_class_custom'],
];
$fields = ['' => $this->t('<None>')];
$fields += $this->displayHandler->getFieldLabels(TRUE);
......
......@@ -34,10 +34,11 @@ class ViewsBootstrapMediaObject extends StylePluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['image_field'] = ['default' => ''];
$options['heading_field'] = ['default' => ''];
$options['image_field'] = ['default' => ''];
$options['image_placement'] = ['default' => 'first'];
$options['image_class'] = ['default' => 'start'];
$options['body_field'] = ['default' => ''];
$options['image_class'] = ['default' => 'media-left'];
return $options;
}
......@@ -56,7 +57,7 @@ class ViewsBootstrapMediaObject extends StylePluginBase {
'#type' => 'select',
'#title' => $this->t('Heading field'),
'#options' => $fields,
'#required' => TRUE,
'#required' => FALSE,
'#default_value' => $this->options['heading_field'],
'#description' => $this->t('Select the field that will be used as the media object heading.'),
];
......@@ -70,13 +71,24 @@ class ViewsBootstrapMediaObject extends StylePluginBase {
'#description' => $this->t('Select the field that will be used as the media object image.'),
];
$form['image_placement'] = [
'#type' => 'radios',
'#title' => $this->t('Image Placement'),
'#options' => [
'first' => $this->t('Left'),
'last' => $this->t('Right'),
],
'#default_value' => $this->options['image_placement'],
'#description' => $this->t('Align the media object image left or right.'),
];
$form['image_class'] = [
'#type' => 'radios',
'#title' => $this->t('Image Alignment'),
'#options' => [
'media-left' => $this->t('Left'),
'media-right' => $this->t('Right'),
'media-middle' => $this->t('Middle'),
'start' => $this->t('Top'),
'center' => $this->t('Middle'),
'end' => $this->t('Bottom'),
],
'#default_value' => $this->options['image_class'],
'#description' => $this->t('Align the media object image left or right.'),
......
......@@ -26,8 +26,9 @@ class ViewsBootstrapTable extends Table {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['bootstrap_styles'] = ['default' => ''];
$options['table_class_custom'] = ['default' => NULL];
$options['responsive'] = ['default' => FALSE];
$options['bootstrap_styles'] = ['default' => NULL];
return $options;
}
......@@ -38,6 +39,18 @@ class ViewsBootstrapTable extends Table {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['help'] = [
'#markup' => $this->t('The Bootstrap table style adds default Bootstrap table classes and optional classes (<a href=":docs">see documentation</a>).', [':docs' => 'https://www.drupal.org/docs/contributed-modules/views-bootstrap-for-bootstrap-3/table']),
'#weight' => -99,
];
$form['table_class_custom'] = [
'#title' => $this->t('Custom table class'),
'#description' => $this->t('Additional classes to provide on the table. Separated by a space.'),
'#type' => 'textfield',
'#default_value' => $this->options['table_class_custom'],
];
$form['responsive'] = [
'#type' => 'checkbox',
'#title' => $this->t('Responsive'),
......@@ -50,10 +63,11 @@ class ViewsBootstrapTable extends Table {
'#type' => 'checkboxes',
'#default_value' => $this->options['bootstrap_styles'],
'#options' => [
'striped' => $this->t('Striped'),
'bordered' => $this->t('Bordered'),
'hover' => $this->t('Hover'),
'borderless' => $this->t('Borderless'),
'sm' => $this->t('Condensed'),
'hover' => $this->t('Hover'),
'striped' => $this->t('Striped'),
],
];
}
......
<div id="{{ id }}" {{ attributes.addClass(classes, 'accordion') }}>
{% if group_title %}
<h3>{{ group_title }}</h3>
{% endif %}
<div id="{{ id }}" {{ attributes }}>
{% set i = 0 %}
{% set len = rows | length %}
{% for key, row in rows -%}
{% for key, row in rows %}
{% set i = i + 1 %}
{% set collapse_var = (
(i == 1 and options.collapse.first is defined and options.collapse.first > 0)
or (i == len and options.collapse.last is defined and options.collapse.last > 0)
or (i != 1 and i != len and options.collapse.middle is defined and options.collapse.middle > 0)
) ? true : false
%}
{% set collapse_var = false %}
{% if behavior == 'specify' %}
{% if i == 1 and 'first' in collapse and collapse['first'] %}
{% set collapse_var = true %}
{% elseif i == len and 'last' in collapse and collapse['last'] %}
{% set collapse_var = true %}
{% elseif i != 1 and i != len and 'middle' in collapse and collapse['middle'] %}
{% set collapse_var = true %}
{% endif %}
{% elseif behavior == 'closed' %}
{% set collapse_var = false %}
{% elseif behavior == 'first' %}
{% set collapse_var = (i == 1) ? true : false %}
{% elseif behavior == 'all' %}
{% set collapse_var = true %}
{% endif %}
{% set collapse_class = (collapse_var) ? 'show' %}
{% set collapse_class_boolean = (collapse_var) ? 'true' : 'false' %}
{% set button_classes = (not collapse_var) ? 'collapsed' %}
<div class="accordion-item">
<h2 class="accordion-header" id="heading{{ key }}">
<button class="accordion-button {{ button_classes }}" type="button" data-bs-toggle="collapse" data-bs-target="#{{ id }}-collapse-{{ key }}" aria-expanded="{{ collapse_class_boolean }}" aria-controls="{{ id }}-collapse-{{ key }}">
{{ row.title }}
</button>
</h2>
<div id="{{ id }}-collapse-{{ key }}" class="accordion-collapse collapse {{ collapse_class }}" aria-labelledby="heading{{ key }}" data-bs-parent="#{{ id }}">
<div class="accordion-body">
{{ row.content }}
</div>
</div>
</div>
{%- endfor %}
{% endfor %}
</div>
......@@ -11,22 +11,30 @@
*/
#}
<div class="card-group">
{% for key, row in rows -%}
<div class="card">
<div {{ attributes.addClass(classes) }}>
<div class="row">
{% for key, row in rows %}
<div class="col">
<div {{ row.attributes.addClass(classes) }}>
{# Show image #}
{% if row.image %}
{{ row.image }}
<span class="card-img-top">{{ row.image }}</span>
{% endif %}
{% if row.content %}
<div class="card-body">
{% if row.title %}
<h5 class="card-title">{{ row.title }}</h5>
{% endif %}
{% if row.content %}
<div class="card-body">
{{ row.content }}
</div>
{% endif %}
</div>
</div>
</div>
{% if (key + 1) % columns == 0 %}
</div><div class="row">
{% endif %}
{%- endfor %}
</div>
</div>
......@@ -19,10 +19,11 @@
'list-group'
]
%}
{% if group_title %}<div{{ create_attribute({'class': div_classes}) }}>{% endif %}
{% if group_title %}<div{{ create_attribute({'class': heading_classes}) }}><h4>{{ group_title }}</h4></div>{% endif %}
<ul id="{{ id }}" {{ attributes.addClass(classes) }}>
{% for key, row in rows %}
<li class="list-group-item">
<li {{ row.attributes }}>
{% if row.title %}
<h4 class="list-group-item-heading">{{ row.title }}</h4>
{% endif %}
......@@ -30,3 +31,4 @@
</li>
{% endfor %}
</ul>
{% if group_title %}</div>{% endif %}
{# @todo: add more control to images and positioning #}
<div{{ attributes.addClass(classes) }} id="{{ id }}">
<div id="{{ id }}">
{% for key, row in rows -%}
<div class="d-flex">
<div class="flex-shrink-0">
<div class="d-flex {{ alignment }}">
<div class="flex-shrink-0 {{ order_image }}">
{% if row.image %}
{{ row.image }}
{% endif %}
</div>
<div class="flex-grow-1 ms-3">
<div class="flex-grow-1 ms-3 {{ order_body }}">
{% if row.heading %}
{{ row.heading }}
{% endif %}
......
......@@ -6,7 +6,7 @@
{% elseif tab_position == 'left' %}
{% set wrapper_classes = wrapper_classes|merge(['d-flex align-items-start']) %}
{% set option_classes = option_classes|merge(['flex-column me-3']) %}
{% set aria_attr = ' aria-origentation="vertical"' %}
{% set aria_attr = ' aria-orientation="vertical"' %}
{% elseif tab_position == 'right' %}
{% set wrapper_classes = wrapper_classes|merge(['d-flex align-items-start']) %}
{% set option_classes = option_classes|merge(['flex-column ms-3']) %}
......
......@@ -20,21 +20,42 @@ use Drupal\views_bootstrap\ViewsBootstrap;
* - view: A ViewExecutable object.
* - rows: The raw row data.
*/
function template_preprocess_views_bootstrap_accordion(array &$vars) {
function template_preprocess_views_bootstrap_accordion(array &$vars): void {
$view = $vars['view'];
$vars['id'] = ViewsBootstrap::getUniqueId($view);
$group_title_field = isset($view->style_plugin->options['grouping'][0]) ? $view->style_plugin->options['grouping'][0]['field'] : "";
$panel_title_field = $view->style_plugin->options['panel_title_field'];
$vars['attributes']['class'][] = 'panel-group';
$vars['options'] = $view->style_plugin->options;
$vars['behavior'] = $view->style_plugin->options['behavior'];
$vars['collapse'] = $view->style_plugin->options['sections'];
$vars['attributes']['class'][] = 'accordion';
if ($view->style_plugin->options['flush']) {
$vars['attributes']['class'][] = 'accordion-flush';
}
if ($panel_title_field) {
foreach ($vars['rows'] as $id => $row) {
$vars['group_title'] = $group_title_field ? $view->style_plugin->getField($id, $group_title_field) : "";
$vars['rows'][$id] = [];
$vars['rows'][$id]['content'] = $row;
$vars['rows'][$id]['title'] = $view->style_plugin->getField($id, $panel_title_field);
$vars['rows'][$id]['title'] = [
'#markup' => Xss::filter($view->style_plugin->getField($id, $panel_title_field), [
'img',
'br',
'h2',
'h3',
'h4',
'h5',
'h6',
'span',
'strong',
'em',
'i',
'small',
]),
];
}
}
else {
// @TODO: This would be better as valdiation errors on the style plugin options form.
// @todo This would be better as validation errors on the style plugin options form.
\Drupal::messenger()->addWarning(t('@style style will not display without the "@field" setting.',
[
'@style' => $view->style_plugin->definition['title'],
......@@ -42,7 +63,7 @@ function template_preprocess_views_bootstrap_accordion(array &$vars) {
]
));
}
// @TODO: Make sure that $vars['rows'] is rendered array.
// @todo Make sure that $vars['rows'] is rendered array.
// @SEE: Have a look template_preprocess_views_view_unformatted()
// and views-view-unformatted.html.twig
}
......@@ -57,9 +78,19 @@ function template_preprocess_views_bootstrap_accordion(array &$vars) {
* - view: A ViewExecutable object.
* - rows: The raw row data.
*/
function template_preprocess_views_bootstrap_cards(array &$vars) {
function template_preprocess_views_bootstrap_cards(array &$vars): void {
$view = $vars['view'];
$vars['id'] = ViewsBootstrap::getUniqueId($view);
$wrapper_attributes = ['class' => ['card-group']];
$classes = array_filter(explode(' ', $view->style_plugin->options['card_group_class_custom']));
foreach ($classes as &$class) {
$class = Html::cleanCssIdentifier($class);
}
if (!empty($classes)) {
$wrapper_attributes['class'] = array_merge($wrapper_attributes['class'], $classes);
}
$vars['attributes'] = new Attribute($wrapper_attributes);
$vars['columns'] = $view->style_plugin->options['columns'];
// Card rows.
$image = $view->style_plugin->options['card_image_field'];
......@@ -71,6 +102,16 @@ function template_preprocess_views_bootstrap_cards(array &$vars) {
$vars['rows'][$id]['image'] = $view->style_plugin->getField($id, $image);
$vars['rows'][$id]['title'] = $view->style_plugin->getField($id, $title);
$vars['rows'][$id]['content'] = $view->style_plugin->getField($id, $content);
$row_attributes = ['class' => ['card']];
// Add custom card classes.
$row_class = array_filter(explode(' ', $view->style_plugin->getCustomClass($id, 'card')));
foreach ($row_class as &$class) {
$class = Html::cleanCssIdentifier($class);
}
if (!empty($row_class)) {
$row_attributes['class'] = array_merge($row_attributes['class'], $row_class);
}
$vars['rows'][$id]['attributes'] = new Attribute($row_attributes);
}
}
......@@ -156,7 +197,7 @@ function template_preprocess_views_bootstrap_carousel(array &$vars): void {
* - view: A ViewExecutable object.
* - rows: The raw row data.
*/
function template_preprocess_views_bootstrap_grid(array &$vars) {
function template_preprocess_views_bootstrap_grid(array &$vars): void {
$view = $vars['view'];
$vars['id'] = ViewsBootstrap::getUniqueId($view);
$vars['attributes']['class'][] = 'grid';
......@@ -183,15 +224,35 @@ function template_preprocess_views_bootstrap_grid(array &$vars) {
* - view: A ViewExecutable object.
* - rows: The raw row data.
*/
function template_preprocess_views_bootstrap_list_group(array &$vars) {
function template_preprocess_views_bootstrap_list_group(array &$vars): void {
$view = $vars['view'];
$options = $view->style_plugin->options;
$vars['id'] = ViewsBootstrap::getUniqueId($view);
$group_title_field = isset($view->style_plugin->options['grouping'][0]) ? $view->style_plugin->options['grouping'][0]['field'] : "";
$vars['attributes']['class'][] = 'views-bootstrap-list-group';
$classes = array_filter(explode(' ', $view->style_plugin->options['list_group_class_custom']));
foreach ($classes as &$list_class) {
$list_class = Html::cleanCssIdentifier($list_class);
}
if (!empty($classes)) {
$vars['attributes']['class'] = array_merge($vars['attributes']['class'], $classes);
}
foreach ($vars['rows'] as $id => $row) {
$vars['group_title'] = $group_title_field ? $view->style_plugin->getField($id, $group_title_field) : "";
$class = $view->style_plugin->options['row_class'];
$classes = explode(' ', $class);
foreach ($classes as &$class) {
$class = Html::cleanCssIdentifier($class);
}
$row_class = array_filter($classes);
$vars['rows'][$id] = [];
$vars['rows'][$id]['content'] = $row;
$vars['rows'][$id]['title'] = $vars['view']->style_plugin->getField($id, $options['title_field']);
$row_attributes = ['class' => ['list-group-item']];
if (!empty($row_class)) {
$row_attributes['class'] = array_merge($row_attributes['class'], $row_class);
}
$vars['rows'][$id]['attributes'] = new Attribute($row_attributes);
}
}
......@@ -206,17 +267,20 @@ function template_preprocess_views_bootstrap_list_group(array &$vars) {
* - view: A ViewExecutable object.
* - rows: The raw row data.
*/
function template_preprocess_views_bootstrap_media_object(array &$vars) {
function template_preprocess_views_bootstrap_media_object(array &$vars): void {
$vars['id'] = ViewsBootstrap::getUniqueId($vars['view']);
$image_class = $vars['view']->style_plugin->options['image_class'];
$image_field = $vars['view']->style_plugin->options['image_field'];
$heading_field = $vars['view']->style_plugin->options['heading_field'];
$body_field = $vars['view']->style_plugin->options['body_field'];
$alignment = $vars['view']->style_plugin->options['image_class'];
$image_placement = $vars['view']->style_plugin->options['image_placement'];
$body_placement = $image_placement == 'first' ? 'last' : 'first';
$vars['alignment'] = "align-items-{$alignment}";
$vars['order_image'] = "order-{$image_placement}";
$vars['order_body'] = "order-{$body_placement}";
foreach ($vars['rows'] as $id => $row) {
$vars['rows'][$id] = [];
$vars['classes'][$id] .= ' media-object';
$vars['rows'][$id]['image_class'] = $image_class;
$vars['rows'][$id]['image'] = $vars['view']->style_plugin->getField($id, $image_field);
$vars['rows'][$id]['heading'] = $vars['view']->style_plugin->getField($id, $heading_field);
$vars['rows'][$id]['body'] = $vars['view']->style_plugin->getField($id, $body_field);
......@@ -295,10 +359,18 @@ function template_preprocess_views_bootstrap_tab(array &$vars): void {
* - view: A ViewExecutable object.
* - rows: The raw row data.
*/
function template_preprocess_views_bootstrap_table(array &$vars) {
$vars['responsive'] = $vars['view']->style_plugin->options['responsive'];
function template_preprocess_views_bootstrap_table(array &$vars): void {
$view = $vars['view'];
$classes = array_filter(explode(' ', $view->style_plugin->options['table_class_custom']));
foreach ($classes as &$class) {
$class = Html::cleanCssIdentifier($class);
}
$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;
}
if (!empty($classes)) {
$vars['attributes']['class'] = array_merge($vars['attributes']['class'], $classes);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment