public static function RenderExampleController::lazyBuilder in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/render_example/src/Controller/RenderExampleController.php \Drupal\render_example\Controller\RenderExampleController::lazyBuilder()
Example #lazy_builder callback.
Demonstrates the use of a #lazy_builder callback to build out a render array that can be substituted into the parent array wherever the cacheable placeholder exists.
This method is called during the process of rendering the array generated by \Drupal\render_example\Controller\RenderExampleController::arrays().
Parameters
string $date_format: Date format to use with \Drupal\Core\Datetime\DateFormatter::format().
Return value
array A renderable array with content to replace the #lazy_builder placeholder.
File
- render_example/
src/ Controller/ RenderExampleController.php, line 488
Class
- RenderExampleController
- Provides module description page and examples of building render arrays.
Namespace
Drupal\render_example\ControllerCode
public static function lazyBuilder($date_format) {
$build = [
'lazy_builder_time' => [
'#markup' => '<p>' . \Drupal::translation()
->translate('The current time is @time', [
'@time' => \Drupal::service('date.formatter')
->format(REQUEST_TIME, 'long'),
]) . '</p>',
],
];
return $build;
}