From 18aed52c27c0263efbdb1a0cc19a9f66f07fe49a Mon Sep 17 00:00:00 2001 From: Brian Tofte-Schumacher <201665+briantschu@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:22:30 -0400 Subject: [PATCH 1/2] Ensure target_id is set --- includes/node.inc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/node.inc b/includes/node.inc index a3b4a517..04e18326 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -39,9 +39,11 @@ function slac_preprocess_node(&$variables) { if($node->get('field_hero_paragraph')->first()) { $hero_field = $node->get('field_hero_paragraph')->first()->getValue(); - /** @var Paragraph $hero_paragraph */ - $hero_paragraph = Paragraph::load($hero_field['target_id']); - $variables['hero_type'] = $hero_paragraph->getType(); + if ($hero_field['target_id']) { + /** @var \Drupal\paragraphs\Entity\Paragraph $hero_paragraph */ + $hero_paragraph = Paragraph::load($hero_field['target_id']); + $variables['hero_type'] = $hero_paragraph->getType(); + } } else { $variables['hero_type'] = 'none'; From 050ae0e65f9a5412151f84c91c3aa4fa8c4cd7ae Mon Sep 17 00:00:00 2001 From: Brian Tofte-Schumacher <201665+briantschu@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:22:40 -0400 Subject: [PATCH 2/2] Beautify --- includes/node.inc | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/includes/node.inc b/includes/node.inc index 04e18326..6712b3db 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -5,7 +5,6 @@ * Node-related hook implementations. */ -use Drupal\Core\Url; use Drupal\node\Entity\Node; use Drupal\paragraphs\Entity\Paragraph; @@ -22,12 +21,6 @@ function slac_preprocess_node(&$variables) { _add_regions_to_template($allowed_regions, $variables); } - // Some content types that may display a table of contents. First check to make - // sure that the view_mode is full (and not card, etc.) indicating that the - // node's detail page is being displayed. If the node is a type that displays a - // table of contents, first find the TOC markers if any in the content - // paragraphs field and then create a themeable list of markers as an array - // that is assigned to a template variable. if ($variables['view_mode'] == 'full') { /** @var \Drupal\node\NodeInterface $node */ $node = $variables['node']; @@ -36,7 +29,7 @@ function slac_preprocess_node(&$variables) { // Determine the type of the hero paragraph if the field exists. if ($node->hasField('field_hero_paragraph')) { - if($node->get('field_hero_paragraph')->first()) { + if ($node->get('field_hero_paragraph')->first()) { $hero_field = $node->get('field_hero_paragraph')->first()->getValue(); if ($hero_field['target_id']) { @@ -69,11 +62,11 @@ function _add_regions_to_template($allowed_regions, &$variables) { // Load blocks from this region and sort them. $blocks = \Drupal::entityTypeManager() ->getStorage('block') - ->loadByProperties(array('theme' => $theme, 'region' => $region)); + ->loadByProperties(['theme' => $theme, 'region' => $region]); uasort($blocks, 'Drupal\block\Entity\Block::sort'); // Build blocks and assign to template variable. - $build = array(); + $build = []; $builder = \Drupal::entityTypeManager()->getViewBuilder('block'); foreach ($blocks as $key => $block) { if ($block->access('view')) { @@ -95,7 +88,7 @@ function slac_preprocess_node__person(&$vars) { 'type' => 'text_trimmed', 'label' => 'hidden', 'settings' => [ - 'trim_length' => 500 + 'trim_length' => 500, ], ]); } @@ -109,7 +102,8 @@ function slac_preprocess_node__news_article(&$vars) { if ($vars['view_mode'] == 'card' || $vars['view_mode'] == 'teaser_card') { if (!empty($vars['content']['field_teaser'][0]) && $vars['content']['field_teaser']['#formatter'] == 'trimmed_first_wysiwyg_paragraph') { $is_truncated = $vars['elements']['field_teaser'][0]['#attributes']['is_truncated']; - } elseif (isset($vars['content']['field_paragraphs']['#formatter']) && $vars['content']['field_paragraphs']['#formatter'] == 'trimmed_first_wysiwyg_paragraph') { + } + elseif (isset($vars['content']['field_paragraphs']['#formatter']) && $vars['content']['field_paragraphs']['#formatter'] == 'trimmed_first_wysiwyg_paragraph') { $is_truncated = $vars['elements']['field_paragraphs'][0]['#attributes']['is_truncated']; } if (isset($is_truncated)) { @@ -119,7 +113,7 @@ function slac_preprocess_node__news_article(&$vars) { if ($vars['view_mode'] == 'full') { $node = $vars['elements']['#node']; if (!$node->field_text->value && $node->field_link->first()) { - /** @var Url $url */ + /** @var \Drupal\Core\Url $url */ $url = $node->field_link->first()->getUrl(); if ($url->getRouteName() === 'entity.node.canonical') { $nid = $url->getRouteParameters()['node']; @@ -141,6 +135,9 @@ function slac_preprocess_node__blog(&$vars) { slac_preprocess_node__news_article($vars); } +/** + * Implements hook_preprocess_node__HOOK(). + */ function slac_preprocess_node__event(&$vars) { $node = $vars['node']; if (method_exists($node, 'getOutlookLink') && isset($vars['content']['field_smart_date'][0]['addtocal']['#outlook'])) {