From 1638ad1b750b41d9cc040365c463ddb0edc4dbb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Fri, 20 Oct 2023 17:40:45 -0400 Subject: [PATCH] Prevent PHP notices on content view modes with no body paragraph --- web/themes/custom/agarica/agarica.theme | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/web/themes/custom/agarica/agarica.theme b/web/themes/custom/agarica/agarica.theme index f33ab51..107e557 100644 --- a/web/themes/custom/agarica/agarica.theme +++ b/web/themes/custom/agarica/agarica.theme @@ -18,6 +18,22 @@ function agarica_preprocess_node(&$variables) { $allowed_regions = ['secondary_menu']; agarica_add_regions_to_node($allowed_regions, $variables); } + $field_body_paragraph = $variables['elements']['field_body_paragraph'] ?? NULL; + if (isset($field_body_paragraph)) { + $max_key = max(array_map('intval', array_keys($field_body_paragraph))); + for ($i = 0; $i <= $max_key; $i++) { + if ($field_body_paragraph[$i]['#paragraph']->getType() === 'title') { + + $renderer = \Drupal::service('renderer'); + + $authors_html = $renderer->render($variables['content']['field_authors']); + $date_html = $variables['date']; + + $field_body_paragraph[$i]['#paragraph']->authors_html = $authors_html; + $field_body_paragraph[$i]['#paragraph']->date_html = $date_html; + } + } + } } /**