function domain_menu_access_form_menu_edit_item_alter in Domain Menu Access 7
Same name and namespace in other branches
- 6 domain_menu_access.admin.inc \domain_menu_access_form_menu_edit_item_alter()
Implementation of hook_form_FORM_ID_alter().
File
- ./
domain_menu_access.admin.inc, line 11 - Domain Menu Access module admin functions.
Code
function domain_menu_access_form_menu_edit_item_alter(&$form, &$form_state) {
if (user_access('administer menus per domain')) {
// Load default values.
$show_default_value = isset($form['original_item']['#value']['options']['domain_menu_access']['show']) ? $form['original_item']['#value']['options']['domain_menu_access']['show'] : array();
$hide_default_value = isset($form['original_item']['#value']['options']['domain_menu_access']['hide']) ? $form['original_item']['#value']['options']['domain_menu_access']['hide'] : array();
// If any of domain boxes are selected, display fieldset as expanded.
$collapsed = count($show_default_value) || count($hide_default_value) ? FALSE : TRUE;
$form['domain_menu_access']['manage'] = array(
'#type' => 'fieldset',
'#title' => t('Manage item visibility per domain'),
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#description' => '<p>' . t('This section allows to show or hide this menu item on selected domains. See <a href="@help_url">module help</a> for more information.', array(
'@help_url' => url('admin/help/domain_menu_access'),
)) . '</p>',
);
// Get list of all available domains.
// Add 'd' to array keys so it is saved properly even for domain_id = 0.
$options = array();
foreach (domain_domains() as $domain) {
$options['d' . $domain['domain_id']] = $domain['sitename'];
}
// Show menu item per domain config.
$form['domain_menu_access']['manage']['domain_menu_access_show'] = array(
'#type' => 'checkboxes',
'#title' => t('Show menu item only on selected domains'),
'#options' => $options,
'#default_value' => $show_default_value,
'#description' => t('Show this menu item only on selected domain(s). If you select no domains, the menu item will be visible on all domains.'),
);
// Hide menu item per domain config.
$form['domain_menu_access']['manage']['domain_menu_access_hide'] = array(
'#type' => 'checkboxes',
'#title' => t('Hide menu item on selected domains'),
'#options' => $options,
'#default_value' => $hide_default_value,
'#description' => t('Hide this menu item on selected domain(s). If you select no domains, the menu item will be visible on all domains.'),
);
// Add weight to Submit button, as it is not set by default by menu.module,
// and because it sets weight of Delete button, it could happen that our
// fieldset is displayed between Save and Delete buttons.
$form['submit']['#weight'] = 9;
// Add own validate function to avoid one menu item
// being both displayed and hidden for the same domain.
$form['#validate'][] = 'domain_menu_access_form_menu_edit_item_validate';
// Make sure that our submit is called before menu_edit_item_submit()
// from Drupal core menu.admin.inc, as there the changes are being saved.
array_unshift($form['#submit'], 'domain_menu_access_form_menu_edit_item_submit');
}
}