public static function RenderCachePlaceholder::postRenderCacheCallback in Render cache 7.2
Generic #post_render_cache callback for getPlaceholder().
Parameters
array $element: The renderable array that contains the to be replaced placeholder.
array $context: An array with the following keys:
- function: The function to call.
- args: The arguments to pass to the function.
Return value
array A renderable array with the placeholder replaced.
Overrides RenderCachePlaceholderInterface::postRenderCacheCallback
File
- src/
Cache/ RenderCachePlaceholder.php, line 84 - Contains \Drupal\render_cache\Cache\RenderCachePlaceholder
Class
- RenderCachePlaceholder
- Provides placeholder utility functions.
Namespace
Drupal\render_cache\CacheCode
public static function postRenderCacheCallback(array $element, array $context) {
$placeholder = static::generatePlaceholder($context['function'], $context);
// Check if the placeholder is present at all.
if (strpos($element['#markup'], $placeholder) === FALSE) {
return $element;
}
$function = $context['function'];
$args = static::loadPlaceholderFunctionArgs($context);
$new_element = call_user_func_array($function, $args);
$markup = static::drupalRender($new_element);
$element['#markup'] = str_replace($placeholder, $markup, $element['#markup']);
return $element;
}