Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WCMS
uw_ct_embedded_call_to_action
Commits
1076f69b
Commit
1076f69b
authored
Feb 07, 2020
by
Eric Bremner
Browse files
ISTWCMS-3591: adding module file and preprocessing function to get out CTA values
parent
d80c4103
Changes
1
Hide whitespace changes
Inline
Side-by-side
uw_ct_embedded_call_to_action.module
0 → 100644
View file @
1076f69b
<?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
;
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment