Commit d7ccc7f7 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-4619: getting variables for teaser in preprocess node

parent 07fe970d
......@@ -27,3 +27,53 @@ function uw_ct_event_geofield_map_latlon_element_alter(array &$map_settings, arr
$complete_form['#attached']['library'][] = 'uw_ct_event/uw_ct_event_edit';
}
}
/**
* Implements hook_preprocess_node().
*
* Set variables for teaser.
*/
function uw_ct_event_preprocess_node(&$variables) {
// If we are on a event node that is a teaser,
// get out the variables to be used in pattern-lab.
if ($variables['node']->getType() == 'uw_ct_event' && $variables['view_mode'] == 'teaser') {
// The UW service object.
$uwService = \Drupal::service('uw_cfg_common.uw_service');
// Get the image entity.
$image = $variables['node']->field_uw_event_listing_page_img->entity;
// If there is an image, get the responsive image sources.
if ($image) {
$sources = $uwService->prepareResponsiveImage($image, 'uw_ris_media');
}
else {
$sources = NULL;
}
// Get the header and footer data from the UW service.
$header_data = $uwService->uwGetHeaderData($variables['node']);
$footer_data = $uwService->uwGetFooterData($variables['node']);
// Set the variables that we can use in the template.
$variables['teaser'] = [
'date' => $header_data['date'],
'title' => $header_data['title'],
'sources' => $sources !== NULL ? $sources['sources'] : '',
'img_element' => $sources !== NULL ? $sources['img_element']['#uri'] : NULL,
'tags' => $footer_data !== NULL ? $footer_data['tags'] : NULL,
'content' => [
'#type' => 'processed_text',
'#text' => $variables['node']->field_uw_event_summary->value,
'#format' => $variables['node']->field_uw_event_summary->format,
],
'header_level' => 2,
];
// Unset the content variable, so that we do not get
// a second print of all the content.
unset($variables['content']);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment