@@ -25,11 +25,16 @@ function psulib_base_helper_theme($existing, $type, $theme, $path): array {
2525 'options' => [],
2626 ],
2727 ],
28- 'views_psulib_base_helper_accordion_content_item' => [
28+ 'views_view_fields__accordion_content' => [
29+ 'base hook' => 'views_view_fields',
30+ 'template' => 'views-view-fields--accordion-content',
31+
2932 'variables' => [
30- 'label' => '',
33+ 'view' => NULL,
34+ 'field' => NULL,
35+ 'row' => NULL,
36+ 'title_field' => 'title',
3137 'options' => [],
32- 'content' => [],
3338 ],
3439 ],
3540 ];
@@ -47,7 +52,7 @@ function psulib_base_helper_preprocess_views_psulib_base_helper_card_grid(&$vari
4752}
4853
4954/**
50- * Prepares variables for views table templates .
55+ * Prepares variables for views accordion template. .
5156 *
5257 * Default template: views-view-table.html.twig.
5358 *
@@ -61,24 +66,26 @@ function template_preprocess_views_psulib_base_helper_accordion(&$variables) {
6166 $view = $variables['view'];
6267 $options = $view->style_plugin->options;
6368 $variables['options'] = $options;
69+ $variables['display_class'] = $view->display_handler->getOption('css_class');
6470 $items = [];
6571
72+ $renderer = \Drupal::service('renderer');
73+
6674 foreach ($view->result as $id => $row) {
67- $item = [];
68- foreach ($view->field as $field_id => $field) {
69- if ($field_id == $options['title_field']) {
70- $item['title'] = $view->style_plugin->getField($id, $field_id);
71- }
72- else {
73- $item['content'][$field_id] = [
74- '#theme' => 'views_psulib_base_helper_accordion_content_item',
75- '#label' => $field->label(),
76- '#options' => $field->options,
77- '#content' => $view->style_plugin->getField($id, $field_id),
78- ];
79- }
80- }
81- $items[] = $item;
75+ // Build the content array. We're extending the views_view_fields theme
76+ // function so we can remove the title field from the content area.
77+ $content = [
78+ '#theme' => 'views_view_fields__accordion_content',
79+ '#view' => $view,
80+ '#options' => $view->rowPlugin->options,
81+ '#title_field' => $options['title_field'],
82+ '#row' => $row,
83+ ];
84+
85+ $items[] = [
86+ 'title' => $view->style_plugin->getField($id, $options['title_field']),
87+ 'content' => $renderer->render($content),
88+ ];
8289 }
8390 $variables['items'] = $items;
8491
0 commit comments