function ctools_context_replace_placeholders
Replace placeholders with real contexts using data extracted from a form for the purposes of previews.
Parameters
$contexts: All of the contexts, including the placeholders.
$arguments: The arguments. These will be acquired from $form_state['values'] and the keys must match the context IDs.
Return value
array A new $contexts array containing the replaced contexts. Not all contexts may be replaced if, for example, an argument was unable to be converted into a context.
File
-
includes/
context.inc, line 1721
Code
function ctools_context_replace_placeholders($contexts, $arguments) {
foreach ($contexts as $cid => $context) {
if (empty($context->empty)) {
continue;
}
$new_context = NULL;
switch ($context->placeholder['type']) {
case 'relationship':
$relationship = $context->placeholder['conf'];
if (isset($contexts[$relationship['context']])) {
$new_context = ctools_context_get_context_from_relationship($relationship, $contexts[$relationship['context']]);
}
break;
case 'argument':
if (isset($arguments[$cid]) && $arguments[$cid] !== '') {
$argument = $context->placeholder['conf'];
$new_context = ctools_context_get_context_from_argument($argument, $arguments[$cid]);
}
break;
case 'context':
if (!empty($arguments[$cid])) {
$context_info = $context->placeholder['conf'];
$new_context = ctools_context_get_context_from_context($context_info, 'requiredcontext', $arguments[$cid]);
}
break;
}
if ($new_context && empty($new_context->empty)) {
$contexts[$cid] = $new_context;
}
}
return $contexts;
}