Commit 1076f69b authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-3591: adding module file and preprocessing function to get out CTA values

parent d80c4103
<?php
/**
* Implements template_preprocess_block().
*/
function uw_ct_embedded_call_to_action_preprocess_block(&$variables) {
// If we are on the CTA, preprocess the values.
if(isset($variables['derivative_plugin_id']) && $variables['derivative_plugin_id'] == 'uw_ebr_cta') {
// Step through each CTA and get out the values.
foreach ($variables['content'][0]['field_uw_cta'] as $key => $cta) {
// If the key is an integer it is a paragraph and we need
// to get out the values from it.
if (is_int($key)) {
// Set a variable with paragraph.
$para = $cta['#paragraph'];
// Get the values of the CTA into an array.
$ctas[] = [
// The link of the CTA.
'link' => $para->get('field_uw_cta_link')->getValue() ? $para->get('field_uw_cta_link')->getValue()[0]['uri'] : NULL,
// The big text of the CTA.
'big_text' => $para->get('field_uw_cta_big_text')->getValue() ? $para->get('field_uw_cta_big_text')->getValue()[0]['value'] : NULL,
// The medium text of the CTA.
'medium_text' => $para->get('field_uw_cta_medium_text')->getValue() ? $para->get('field_uw_cta_medium_text')->getValue()[0]['value'] : NULL,
// The small text of the CTA.
'small_text' => $para->get('field_uw_cta_small_text')->getValue() ? $para->get('field_uw_cta_small_text')->getValue()[0]['value'] : NULL,
// The theme of the CTA.
'theme' => $para->get('field_uw_cta_theme')->getValue()[0]['value'],
];
}
}
// If there is CTAS that were processed, unset the content variable
// and set the ctas variables.
if (isset($ctas)) {
// Unset content variable.
unset($variables['content']);
// Set the ctas variable.
$variables['ctas'] = $ctas;
}
}
}
Supports Markdown
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