You are here

public static function RenderCachePlaceholder::getPlaceholder in Render cache 7.2

Gets a #post_render_cache placeholder for a given function.

Parameters

$function: The function to call when the #post_render_cache callback is invoked.

array $args: The arguments to pass to the function. This can contain %load arguments, similar to how menu paths are working.

$args = array(
  '%node' => $node->nid,
  'full',
);

Given %node the function node_load() will be called with the argument, the resulting function will just be given the $node as argument.

This can be any valid callable, so also %MyClass::staticMethod, where MyClass::staticMethodLoad() is called.

bool $multiple: Whether the function accepts multiple contexts. This is useful to group similar objects together.

Return value

array A render array with #markup set to the placeholder and #post_render_cache callback set to callback postRenderCacheCallback() with the given arguments and function encoded in the context.

Overrides RenderCachePlaceholderInterface::getPlaceholder

2 calls to RenderCachePlaceholder::getPlaceholder()
BaseController::getPlaceholders in src/RenderCache/Controller/BaseController.php
Get the placeholders from the cache information map.
render_cache_comment_node_view in modules/utility/render_cache_comment/render_cache_comment.module
Implements hook_node_view()

File

src/Cache/RenderCachePlaceholder.php, line 21
Contains \Drupal\render_cache\Cache\RenderCachePlaceholder

Class

RenderCachePlaceholder
Provides placeholder utility functions.

Namespace

Drupal\render_cache\Cache

Code

public static function getPlaceholder($function, array $args = array(), $multiple = FALSE) {

  // Add the classname to the front.
  $callback = get_called_class();
  $callback .= $multiple ? '::postRenderCacheMultiCallback' : '::postRenderCacheCallback';
  $context = array(
    'function' => $function,
    'args' => $args,
  );
  $placeholder = static::generatePlaceholder($context['function'], $context);
  $context = array(
    $context,
  );
  if ($multiple) {
    $context = array(
      $function => $context,
    );
  }
  return array(
    '#post_render_cache' => array(
      $callback => $context,
    ),
    '#markup' => $placeholder,
  );
}