diff --git a/API.txt b/API.txt index b7fca15cf76b1368437318a2ad5c58633e7ecc6e..767dd9746a09bd0e7421af4f2bcfcb4955cf38ea 100644 --- a/API.txt +++ b/API.txt @@ -4,7 +4,8 @@ This file contains a log of changes to the API. API version 1.1.1: Introduce ctools_plugin_get_class() and ctools_plugin_load_class() - Introdue ctools_ajax_command_attr(). + Introduce ctools_ajax_command_attr(). + Introduce ctools_set_page_token(). API version 1.1.0: delegator module destroyed, replaced by page manager. All 'task' and 'task_handler' plugins diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d08e1feae286afb2a29400740f1ef44de6668794..e7a824cccb4984aad947caef9bce17aae69500bc 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -17,6 +17,7 @@ Make sure that tasks that will not override existing overrides refuse to enable #478542 by nickl: Add "attr" command to ajax framework. #495240 by mikl: Blob handling for pgsql. #531936: Cache handling on contexts was spotty and could cause random errors. +#545540 by Roger López: Add 5 page elements as available panes for using Panels as your primary page layout: breadcrumb, page title, messages, tabs and help box. ctools 6.x-1.0-rc1 ================== diff --git a/ctools.module b/ctools.module index 9bc825690cdae9bc89326b3b2e1b80de4c59ffd7..5a03d308463dbf07fd631067ab61a1f64db2e382 100644 --- a/ctools.module +++ b/ctools.module @@ -360,3 +360,60 @@ function ctools_js_load($js) { } return 0; } + +/** + * A theme preprocess function to allow content type plugins to use page + * template variables which are not yet available when the content type is + * rendered. + */ +function ctools_preprocess_page(&$variables) { + $tokens = ctools_set_page_token(); + if (!empty($tokens)) { + foreach ($tokens as $token => $key) { + list($type, $argument) = $key; + switch ($type) { + case 'variable': + $tokens[$token] = isset($variables[$argument]) ? $variables[$argument] : ''; + break; + case 'callback': + if (is_string($argument) && function_exists($argument)) { + $tokens[$token] = $argument(); + } + if (is_array($argument) && function_exists($argument[0])) { + $tokens[$token] = call_user_func_array($argument); + } + break; + } + $variables['content'] = strtr($variables['content'], $tokens); + } + } +} + +/** + * Set a token/value pair to be replaced later in the request, specifically in + * ctools_preprocess_page(). + * + * @param $token + * The token to be replaced later, during page rendering. This should + * ideally be a string inside of an HTML comment, so that if there is + * no replacement, the token will not render on the page. + * @param $type + * The type of the token. Can be either 'variable', which will pull data + * directly from the page variables + * @param $argument + * If $type == 'variable' then argument should be the key to fetch from + * the $variables. If $type == 'callback' then it should either be the + * callback, or an array that will be sent to call_user_func_array(). + * + * @return + * A array of token/variable names to be replaced. + */ +function ctools_set_page_token($token = NULL, $type = NULL, $argument = NULL) { + static $tokens = array(); + + if (isset($token)) { + $tokens[$token] = array($type, $argument); + } + + return $tokens; +} \ No newline at end of file