function RenderExampleController::preRenderAddSuffix
Same name in other branches
- 3.x modules/render_example/src/Controller/RenderExampleController.php \Drupal\render_example\Controller\RenderExampleController::preRenderAddSuffix()
Example '#pre_render' function.
Pre render callbacks are triggered prior to rendering an element to HTML and are given the chance to manipulate the renderable array. Any changes they make will be reflected in the final rendered HTML.
We need to wrap suffix in a Markup object. Otherwise, style attribute will be removed by Xss
Parameters
array $element: The element which will be rendered.
Return value
array The altered element. In this case we add a #prefix to it.
See also
\Drupal\Component\Utility\Xss::filter()
This function is used as a post render callback in \Drupal\render_example\Controller\RenderExampleController::arrays().
\Drupal\render_example\Controller\RenderExampleController::arrays()
File
-
modules/
render_example/ src/ Controller/ RenderExampleController.php, line 547
Class
- RenderExampleController
- Provides module description page and examples of building render arrays.
Namespace
Drupal\render_example\ControllerCode
public static function preRenderAddSuffix(array $element) {
$element['#suffix'] = Markup::create('<div style="color:red">' . t('This #suffix was added by a #pre_render callback.') . '</div>');
return $element;
}