You are here

public function BaseRecursionController::recursionStep in Render cache 7.2

Ensures that recursion storage is added to the right cached object.

Example: A module can implement hook_block_view_alter() and pass $block->content to ensure that recursion storage created during the building of the block is properly added to the block itself: {

?>
<?php}
function render_cache_block_block_view_alter(&$data, $block) {
  if (!empty($block->render_cache_controller) && !empty($data['content'])) {
    // Normalize to the drupal_render() structure so we can add something.
    if (is_string($data['content'])) {
      $data['content'] = array(
        '#markup' => $data['#content'],
      );
    }
    $block->render_cache_controller->recursionStep($data['content']);
  }
}
{?><?php

}

Parameters

$build: The render array to add the recursion storage to when the $build is not empty.

Overrides RecursionControllerInterface::recursionStep

File

src/RenderCache/Controller/BaseRecursionController.php, line 21
Contains \Drupal\render_cache\RenderCache\Controller\BaseRecursionController

Class

BaseRecursionController
Base class for RecursionController plugin objects.

Namespace

Drupal\render_cache\RenderCache\Controller

Code

public function recursionStep(array &$build) {
  $storage = $this->renderStack
    ->decreaseRecursion();
  if (!empty($build)) {
    $build['x_render_cache_recursion_storage'] = $storage;
  }
  $this->renderStack
    ->increaseRecursion();
}