From 979ff8af7b64c98cf12ecc159b82cf0c7cc8e4dd Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Wed, 9 Jun 2021 15:49:38 -0400 Subject: [PATCH] ISTWCMS-4704: centralizing preprocess node function for full and teaser nodes --- uw_fdsu_theme_resp.theme | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index 0c6e727f..abc415e0 100644 --- a/uw_fdsu_theme_resp.theme +++ b/uw_fdsu_theme_resp.theme @@ -330,6 +330,44 @@ function _uw_fdsu_theme_resp_get_image_info(FileFieldItemList $field) { } } +/** + * Implements hook_preprocess_node(). + * + * Set variables for node and teaser. + */ +function uw_fdsu_theme_resp_preprocess_node(&$variables) { + + // The types of nodes the need preprocessing. + $nodes_to_preprocess = [ + 'uw_ct_blog', + 'uw_ct_event', + 'uw_ct_news_item', + ]; + + // If there is a node that needs preprocessing, + // set the appropriate variables. + if (in_array($variables['node']->getType(), $nodes_to_preprocess)) { + + // The UW service object. + $uwService = \Drupal::service('uw_cfg_common.uw_service'); + + // If on a teaser page get the variables for teaser. + if ($variables['view_mode'] == 'teaser') { + $variables['teaser'] = $uwService->uwGetNodeContent($variables['node'], 'teaser', 'all'); + } + + // If on a node page get the variables for now. + if ($variables['view_mode'] == 'full') { + $variables['node_data'] = $uwService->uwGetNodeContent($variables['node'], 'full', 'all'); + $variables['node_data']['content'] = $variables['content']; + } + + // Unset the content variable, so that we do not get + // a second print of all the content. + unset($variables['content']); + } +} + /** * Implements hook_preprocess_block(). * -- GitLab