Commit 1daa6bb3 authored by catch's avatar catch

Issue #2118703 by Wim Leers, amateescu: Introduce #post_render_cache callback...

Issue #2118703 by Wim Leers, amateescu: Introduce #post_render_cache callback to allow for personalization without breaking the render cache.
parent 996fb572
This diff is collapsed.
......@@ -599,6 +599,13 @@ function system_element_info() {
'#theme' => 'table',
);
// Other elements.
$types['render_cache_placeholder'] = array(
'#callback' => '',
'#context' => array(),
'#pre_render' => array('drupal_pre_render_render_cache_placeholder'),
);
return $types;
}
......
......@@ -197,3 +197,63 @@ function common_test_library_info() {
function common_test_cron() {
throw new Exception(t('Uncaught exception'));
}
/**
* #post_render_cache callback; modifies #markup, #attached and #context_test.
*
* @param array $element
* A render array with the following keys:
* - #markup
* - #attached
* @param array $context
* An array with the following keys:
* - foo: contains a random string.
*
* @return array $element
* The updated $element.
*/
function common_test_post_render_cache(array $element, array $context) {
// Override #markup.
$element['#markup'] = '<p>overridden</p>';
// Extend #attached.
$element['#attached']['js'][] = array(
'type' => 'setting',
'data' => array(
'common_test' => $context
),
);
// Set new property.
$element['#context_test'] = $context;
return $element;
}
/**
* #post_render_cache callback; replaces placeholder, extends #attached.
*
* @param array $context
* An array with the following keys:
* - bar: contains a random string.
*
* @return array
* A render array.
*/
function common_test_post_render_cache_placeholder(array $context) {
$element = array(
'#markup' => '<bar>' . $context['bar'] . '</bar>',
'#attached' => array(
'js' => array(
array(
'type' => 'setting',
'data' => array(
'common_test' => $context,
),
),
),
),
);
return $element;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment