function RenderExampleController::lazyBuilder

Same name in other branches
  1. 8.x-1.x render_example/src/Controller/RenderExampleController.php \Drupal\render_example\Controller\RenderExampleController::lazyBuilder()
  2. 4.0.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

modules/render_example/src/Controller/RenderExampleController.php, line 488

Class

RenderExampleController
Provides module description page and examples of building render arrays.

Namespace

Drupal\render_example\Controller

Code

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(\Drupal::time()->getRequestTime(), 'long'),
            ]) . '</p>',
        ],
    ];
    return $build;
}