function ack_menu_overview_form in Access Control Kit 7
Form for editing the menu tree for a realm.
Shows all of the menu links for the given realm and relevant operations.
Parameters
object $scheme: An access scheme.
int $realm: A realm value.
Return value
array A form array.
See also
ack_menu_overview_form_submit()
1 string reference to 'ack_menu_overview_form'
- ack_menu_menu in ack_menu/
ack_menu.module - Implements hook_menu().
File
- ack_menu/
ack_menu.pages.inc, line 117 - Page callbacks for managing menu links in assigned realms.
Code
function ack_menu_overview_form($form, &$form_state, $scheme, $realm) {
global $menu_admin;
module_load_include('inc', 'menu', 'menu.admin');
$form['#attached']['css'] = array(
drupal_get_path('module', 'menu') . '/menu.css',
);
$form_state['scheme'] = $scheme;
$form_state['realm'] = $realm;
if (isset($scheme->handlers['menu_link'])) {
$links = ack_menu_realm_links($scheme, $realm);
if (!empty($links)) {
$tree = ack_menu_tree_data($links);
$count = count($tree);
// Loop through the links at the top level of the tree.
foreach ($tree as $data) {
$item = $data['link'];
// Don't show callbacks; these have $item['hidden'] < 0.
if ($item && $item['hidden'] >= 0) {
_menu_link_translate($item);
$element = array(
'#type' => $count > 1 ? 'fieldset' : 'container',
'#tree' => TRUE,
);
if ($count > 1) {
$element['#title'] = l($item['title'], $item['href'], $item['localized_options']);
}
$destination = drupal_get_destination();
$element['link'] = array(
'#type' => 'link',
'#title' => t('Edit the parent link'),
'#href' => 'admin/structure/menu/item/' . $item['mlid'] . '/edit',
'#prefix' => '<ul class="action-links"><li>',
'#suffix' => '</li></ul>',
'#options' => array(
'query' => $destination,
),
);
$element['depth'] = array(
'#type' => 'value',
'#value' => $item['depth'],
);
if (!empty($data['below'])) {
// Build the subtree form in the same way as menu_overview_form().
$node_links = array();
menu_tree_collect_node_links($data['below'], $node_links);
$menu_admin = TRUE;
menu_tree_check_access($data['below'], $node_links);
$menu_admin = FALSE;
drupal_static_reset('_menu_overview_tree_form');
$element['subtree'] = _menu_overview_tree_form($data['below']);
$element['subtree']['#theme'] = 'menu_overview_form';
foreach (element_children($element['subtree']) as $key) {
// Adjust depth so links cannot be moved above the subtree parent.
if (isset($element['subtree'][$key]['#item'])) {
$element['subtree'][$key]['#item']['depth'] -= $item['depth'];
// Remove the edit/delete links for inaccessible branches.
if (!ack_menu_link_access($element['subtree'][$key]['#item'])) {
$element['subtree'][$key]['operations'] = array();
}
}
// Set the redirect destination on the edit/delete links.
foreach (element_children($element['subtree'][$key]['operations']) as $op) {
$element['subtree'][$key]['operations'][$op]['#options']['query'] = $destination;
}
}
}
$form[$item['mlid']] = $element;
}
}
}
}
if (element_children($form)) {
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => 'ack_menu',
);
}
else {
$form['empty'] = array(
'#type' => 'markup',
'#markup' => t('There are no menu links yet for @realm. <a href="@link">Add a link</a>.', array(
'@realm' => $scheme->realms[$realm],
'@link' => url('ack_menu/manage/' . $scheme->machine_name . '/' . $realm . '/add'),
)),
);
}
return $form;
}