public static function Marquee::preRenderMarquee in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/render_example/src/Element/Marquee.php \Drupal\render_example\Element\Marquee::preRenderMarquee()
Pre-render callback; Process custom attribute options.
Parameters
array $element: The renderable array representing the element with '#type' => 'marquee' property set.
Return value
array The passed in element with changes made to attributes depending on context.
File
- render_example/
src/ Element/ Marquee.php, line 80
Class
- Marquee
- Provides a marquee render element.
Namespace
Drupal\render_example\ElementCode
public static function preRenderMarquee(array $element) {
// Normal attributes for a <marquee> tag do not include a 'random' option
// for scroll amount. Our marquee element type does though. So we use this
// #pre_render callback to check if the element was defined with the value
// 'random' for the scrollamount attribute, and if so replace the string
// with a random number.
if ($element['#attributes']['scrollamount'] == 'random') {
$element['#attributes']['scrollamount'] = abs(rand(1, 50));
}
return $element;
}