You are here

interface RenderCachePlaceholderInterface in Render cache 7.2

Defines an interface for #post_render_cache placeholders.

Hierarchy

Expanded class hierarchy of RenderCachePlaceholderInterface

All classes that implement RenderCachePlaceholderInterface

File

src/Cache/RenderCachePlaceholderInterface.php, line 14
Contains \Drupal\render_cache\Cache\RenderCachePlaceholderInterface

Namespace

Drupal\render_cache\Cache
View source
interface RenderCachePlaceholderInterface {

  /**
   * Gets a #post_render_cache placeholder for a given function.
   *
   * @param $function
   *   The function to call when the #post_render_cache callback is invoked.
   * @param array $args
   *   The arguments to pass to the function. This can contain %load arguments,
   *   similar to how menu paths are working.
   *   @code
   *     $args = array(
   *       '%node' => $node->nid,
   *       'full',
   *     );
   *   @endcode
   *   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.
   *
   * @param bool $multiple
   *   Whether the function accepts multiple contexts. This is useful to group similar objects
   *   together.
   *
   * @return 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.
   */
  public static function getPlaceholder($function, array $args = array(), $multiple = FALSE);

  /**
   * Generic #post_render_cache callback for getPlaceholder().
   *
   * @param array $element
   *   The renderable array that contains the to be replaced placeholder.
   * @param array $context
   *   An array with the following keys:
   *   - function: The function to call.
   *   - args: The arguments to pass to the function.
   *
   * @return array
   *   A renderable array with the placeholder replaced.
   */
  public static function postRenderCacheCallback(array $element, array $context);

  /**
   * Generic #post_render_cache callback for getPlaceholder() with multi=TRUE.
   *
   * This is useful to group several related elements together.
   *
   * @param array $element
   *   The renderable array that contains the to be replaced placeholders.
   * @param array $contexts
   *   An array keyed by function with the contexts as values.
   *
   * @return array
   *   A renderable array with the placeholders replaced.
   */
  public static function postRenderCacheMultiCallback(array $element, array $contexts);

  /**
   * Loads the %load arguments within $context['args'].
   *
   * @see RenderCachePlaceholderInterface::getPlaceholder()
   *
   * @param array $context
   *   An array with the following keys:
   *   - function: The function to call.
   *   - args: The arguments to process.
   *
   * @return array
   *   The function arguments suitable for call_user_func_array() with
   *   an argument keyed %node with a value of nid replaced with the loaded
   *   $node.
   */
  public static function loadPlaceholderFunctionArgs(array $context);

}

Members

Namesort descending Modifiers Type Description Overrides
RenderCachePlaceholderInterface::getPlaceholder public static function Gets a #post_render_cache placeholder for a given function. 1
RenderCachePlaceholderInterface::loadPlaceholderFunctionArgs public static function Loads the %load arguments within $context['args']. 1
RenderCachePlaceholderInterface::postRenderCacheCallback public static function Generic #post_render_cache callback for getPlaceholder(). 1
RenderCachePlaceholderInterface::postRenderCacheMultiCallback public static function Generic #post_render_cache callback for getPlaceholder() with multi=TRUE. 1