function context_context_reactions in Context 6
Same name and namespace in other branches
- 6.2 context.core.inc \context_context_reactions()
Implementation of hook_context_reactions().
Allows modules to integrate with context and provide options for responding when a context has been set. The hook should return an array of items keyed on the "type" of getter (e.g. "menu", "theme", etc.) with key-value pairs corresponding to a FormAPI element array with some restrictions and additional info.
The getter element array provided differs from the setter array in that it may store a tree of values (i.e. where #tree => true). The values will be stored in a serialized array in the database.
'#title': Required. The title of the object / form option. '#type': Required. The FormAPI element type to use. Currently only 'select', 'checkboxes', 'radio', and 'textfield' are allowed. '#description': Optional. Help text to be displayed on the form. '#options': Required. A key-value array of options. They key will be stored and passed to context_set_by_condition(), so the integrating module should use a unique (within its namespace) / usable identifier.
File
- ./
context.core.inc, line 157
Code
function context_context_reactions() {
$items = array();
// Menu
if (module_exists('menu')) {
$menus = menu_parent_options(array_reverse(menu_get_menus()), NULL);
$root_menus = array();
foreach ($menus as $key => $name) {
$id = explode(':', $key);
if ($id[1] == '0') {
$root_menus[$id[0]] = check_plain($name);
}
else {
$link = menu_link_load($id[1]);
$root_menu = $root_menus[$id[0]];
$menus[$root_menu][$link['link_path']] = $name;
}
unset($menus[$key]);
}
array_unshift($menus, "-- " . t('None') . " --");
$items['menu'] = array(
'#title' => t('Active menu'),
'#description' => t('Display the selected menu item as active when this context is set. To use this feature, you must use <strong>theme_context_links()</strong> to theme your links. Please see README.txt for more information.'),
'#options' => $menus,
'#type' => 'select',
);
}
// Implements context-based theme improvements
$items['theme_section'] = array(
'#tree' => true,
'#title' => t('Theme variables'),
'title' => array(
'#title' => t('Section title'),
'#description' => t('Provides this text as a <strong>$section_title</strong> variable for display in page.tpl.php when this context is active.'),
'#type' => 'textfield',
'#maxlength' => 255,
),
'subtitle' => array(
'#title' => t('Section subtitle'),
'#description' => t('Provides this text as a <strong>$section_subtitle</strong> variable for display in page.tpl.php when this context is active.'),
'#type' => 'textfield',
'#maxlength' => 255,
),
'class' => array(
'#title' => t('Section class'),
'#description' => t('Provides this text as an additional body class (in <strong>$body_classes</strong> in page.tpl.php) when this section is active. Note that there may only be <strong>one</strong> active section class at once.'),
'#type' => 'textfield',
'#maxlength' => 64,
),
);
// Implements context-based region disabling
$theme_key = variable_get('theme_default', 'garland');
$regions = system_region_list($theme_key);
$items['theme_regiontoggle'] = array(
'#title' => t('Disabled regions'),
'#type' => 'checkboxes',
'#options' => $regions,
);
return $items;
}