function context_reaction_menu::options_form in Context 7.3
Same name and namespace in other branches
- 6.3 plugins/context_reaction_menu.inc \context_reaction_menu::options_form()
- 6 plugins/context_reaction_menu.inc \context_reaction_menu::options_form()
Provide a form element that allow the admin to chose a menu item.
Overrides context_reaction::options_form
File
- plugins/
context_reaction_menu.inc, line 10
Class
- context_reaction_menu
- Expose menu items as context reactions.
Code
function options_form($context) {
$options = array(
"-- " . t('None') . " --",
);
if (module_exists('menu')) {
$menus = menu_parent_options(menu_get_menus(), array(
'mlid' => 0,
));
$menu_names = array();
foreach ($menus as $id => $title) {
list($menu_name, $mlid) = explode(':', $id);
// Store the title each menu for reference.
if ($mlid == '0') {
$menu_names[$menu_name] = $title;
}
else {
$link = menu_link_load($mlid);
$identifier = $link['link_path'];
$root_menu = $menu_names[$menu_name];
while (isset($options[$root_menu][$menu_name . ':' . $identifier])) {
$identifier .= "'";
}
$options[$root_menu][$menu_name . ':' . $identifier] = $title;
}
}
}
$menu_count = count($options, COUNT_RECURSIVE);
return array(
'#title' => $this->title,
'#description' => $this->description,
'#options' => $options,
'#type' => 'select',
'#multiple' => TRUE,
'#size' => $menu_count > 20 ? 20 : $menu_count,
'#default_value' => $this
->fetch_from_context($context),
);
}