1.20.x layout.admin.inc | layout_contexts_form_element(array $available_contexts, array $current_context_settings, array $info) |
Partial form to generate a select list for selecting context.
Parameters
LayoutContext[] $available_contexts: An array of contexts from a layout, as retrieved by Layout::getContexts().
array $info: An array of block or condition info, as provided by layout_get_access_info() or layout_get_block_info(). The list of required contexts is pulled from here (if any).
array $current_context_settings: An array of current context settings, used for populating the defaults.
Return value
array: The partial form element.
File
- modules/
layout/ layout.admin.inc, line 2662 - Admin page callbacks for the Layout module.
Code
function layout_contexts_form_element(array $available_contexts, array $current_context_settings, array $info) {
$element = array(
'#tree' => TRUE,
'#weight' => -20,
);
if (isset($info['required contexts'])) {
foreach ($info['required contexts'] as $context_key => $context_type) {
if (isset($info['required contexts labels'][$context_key])) {
$label = $info['required contexts labels'][$context_key];
}
else {
$context_info = layout_get_context_info($context_type);
$label = $context_info['title'];
}
$options = array();
foreach ($available_contexts as $layout_context_key => $context) {
if ($context->plugin === $context_type) {
$options[$layout_context_key] = $context->label();
}
}
if (count($options) > 1) {
$element[$context_key] = array(
'#type' => 'select',
'#title' => check_plain($label),
'#default_value' => isset($current_context_settings[$context_key]) ? $current_context_settings[$context_key] : NULL,
'#options' => $options,
);
}
}
}
return $element;
}