function _groupmenu_add_menufieldset in Group Menu 7
Adds a standard menu fieldset to a form, mainly copied from menu.module.
Parameters
array $form: The form we will add a menu field set to.
array $options: The menu options return by menu_parent_options().
array $link: The menu link item array.
2 calls to _groupmenu_add_menufieldset()
- groupmenu_form_group_form_alter in ./
groupmenu.module - Implements hook_form_FORM_ID_alter().
- groupmenu_form_node_form_alter in ./
groupmenu.module - Implements hook_form_FORMID_alter().
File
- ./
groupmenu.module, line 779 - Integrates menu with Group.
Code
function _groupmenu_add_menufieldset(array &$form, array $options, array $link) {
$form['menu'] = array(
'#type' => 'fieldset',
'#title' => t('Menu settings'),
'#collapsible' => TRUE,
'#collapsed' => !$link['link_title'],
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(
drupal_get_path('module', 'menu') . '/menu.js',
),
),
'#tree' => TRUE,
'#weight' => -2,
'#attributes' => array(
'class' => array(
'menu-link-form',
),
),
);
$form['menu']['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Provide a menu link'),
'#default_value' => (int) (bool) $link['mlid'],
);
$form['menu']['link'] = array(
'#type' => 'container',
'#parents' => array(
'menu',
),
'#states' => array(
'invisible' => array(
'input[name="menu[enabled]"]' => array(
'checked' => FALSE,
),
),
),
);
// Populate the element with the link data.
$elements = array(
'mlid',
'module',
'hidden',
'has_children',
'customized',
'options',
'expanded',
'hidden',
'parent_depth_limit',
);
foreach ($elements as $key) {
$form['menu']['link'][$key] = array(
'#type' => 'value',
'#value' => $link[$key],
);
}
$form['menu']['link']['link_title'] = array(
'#type' => 'textfield',
'#title' => t('Menu link title'),
'#default_value' => $link['link_title'],
);
$form['menu']['link']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => isset($link['options']['attributes']['title']) ? $link['options']['attributes']['title'] : '',
'#rows' => 1,
'#description' => t('Shown when hovering over the menu link.'),
);
$default = $link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : NULL;
if (!isset($options[$default])) {
$array = array_keys($options);
$default = reset($array);
}
$form['menu']['link']['parent'] = array(
'#type' => 'select',
'#title' => t('Parent item'),
'#default_value' => $default,
'#options' => $options,
'#attributes' => array(
'class' => array(
'menu-parent-select',
),
),
);
$form['menu']['link']['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 50,
'#default_value' => $link['weight'],
'#description' => t('Menu links with smaller weights are displayed before links with larger weights.'),
);
}