You are here

protected function BaseRecursionController::renderRecursive in Render cache 7.2

Renders uncached objects in a recursion compatible way.

The default implementation is dumb and expensive performance wise, as it calls the render() method for each object seperately.

Controllers that support recursions should implement the RecursionControllerInterface and subclass from BaseRecursionController.

Parameters

object[] $objects: Array of $objects to be rendered keyed by id.

Return value

array[] Render array keyed by id.

Overrides BaseController::renderRecursive

See also

\Drupal\render_cache\RenderCache\Controller\RecursionControllerInterface

\Drupal\render_cache\RenderCache\Controller\BaseRecursionController

File

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

Class

BaseRecursionController
Base class for RecursionController plugin objects.

Namespace

Drupal\render_cache\RenderCache\Controller

Code

protected function renderRecursive(array $objects) {

  // This provides an optimized version for rendering in a
  // recursive way.
  //
  // @see BaseController::renderRecursive()
  // Store the render cache controller within the objects.
  foreach ($objects as $object) {
    if (is_object($object)) {
      $object->render_cache_controller = $this;
    }
  }

  // Increase recursion for the first step.
  $this->renderStack
    ->increaseRecursion();

  // Now build the objects, the implementing class
  // is responsible to call recursionStep()
  // after each object has been individually built.
  $build = $this
    ->render($objects);

  // Decrease recursion as the last step.
  $this->renderStack
    ->decreaseRecursion();

  // Remove the render cache controller within the objects again.
  foreach ($objects as $object) {
    if (is_object($object)) {
      unset($object->render_cache_controller);
    }
  }
  return $build;
}