Drupal: applay menu patch
This commit is contained in:
parent
e710b864bc
commit
c9eaa17e24
@ -59,6 +59,14 @@ function menu_overview_form($form, &$form_state, $menu) {
|
||||
foreach ($result as $item) {
|
||||
$links[] = $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1KA iskanje
|
||||
*/
|
||||
$link_count = db_query("SELECT COUNT(*) AS counter FROM {menu_links} WHERE menu_name = :menu AND link_path NOT LIKE :link_path", array(':menu' => $menu['menu_name'], ':link_path' => '%\%%'))->fetchObject();
|
||||
$counter = intval($link_count->counter / 2 ) + 1;
|
||||
|
||||
|
||||
$tree = menu_tree_data($links);
|
||||
$node_links = array();
|
||||
menu_tree_collect_node_links($tree, $node_links);
|
||||
@ -67,7 +75,12 @@ function menu_overview_form($form, &$form_state, $menu) {
|
||||
menu_tree_check_access($tree, $node_links);
|
||||
$menu_admin = FALSE;
|
||||
|
||||
$form = array_merge($form, _menu_overview_tree_form($tree));
|
||||
/**
|
||||
* 1KA menu
|
||||
*/
|
||||
$delta = _menu_get_menu_weight_delta($menu['menu_name'], $counter);
|
||||
$form = array_merge($form, _menu_overview_tree_form($tree, $delta));
|
||||
|
||||
$form['#menu'] = $menu;
|
||||
|
||||
if (element_children($form)) {
|
||||
@ -87,9 +100,10 @@ function menu_overview_form($form, &$form_state, $menu) {
|
||||
* Recursive helper function for menu_overview_form().
|
||||
*
|
||||
* @param $tree
|
||||
* The menu_tree retrieved by menu_tree_data.
|
||||
* * @param $delta
|
||||
* The number of items to use in the menu weight selector. Defaults to 50.
|
||||
*/
|
||||
function _menu_overview_tree_form($tree) {
|
||||
function _menu_overview_tree_form($tree, $delta = 50) {
|
||||
$form = &drupal_static(__FUNCTION__, array('#tree' => TRUE));
|
||||
foreach ($tree as $data) {
|
||||
$title = '';
|
||||
@ -115,7 +129,7 @@ function _menu_overview_tree_form($tree) {
|
||||
);
|
||||
$form[$mlid]['weight'] = array(
|
||||
'#type' => 'weight',
|
||||
'#delta' => 50,
|
||||
'#delta' => $delta,
|
||||
'#default_value' => $item['weight'],
|
||||
'#title_display' => 'invisible',
|
||||
'#title' => t('Weight for @title', array('@title' => $item['title'])),
|
||||
@ -143,7 +157,8 @@ function _menu_overview_tree_form($tree) {
|
||||
}
|
||||
|
||||
if ($data['below']) {
|
||||
_menu_overview_tree_form($data['below']);
|
||||
# 1ka menu $delta
|
||||
_menu_overview_tree_form($data['below'], $delta);
|
||||
}
|
||||
}
|
||||
return $form;
|
||||
@ -358,10 +373,25 @@ function menu_edit_item($form, &$form_state, $type, $item, $menu) {
|
||||
'#description' => t('The maximum depth for a link and all its children is fixed at !maxdepth. Some menu links may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
|
||||
'#attributes' => array('class' => array('menu-title-select')),
|
||||
);
|
||||
|
||||
/**
|
||||
* 1ka menu
|
||||
*/
|
||||
// Get number of items in all possible parent menus so the weight selector is sized appropriately.
|
||||
$menu_names = array_keys(menu_get_menus());
|
||||
$menu_options = array();
|
||||
foreach ($menu_names as $menu_name) {
|
||||
if (isset($options[$menu_name . ':0'])) {
|
||||
$menu_options[] = $menu_name;
|
||||
}
|
||||
}
|
||||
// Make sure that we always have values in menu_options.
|
||||
$menu_options = !empty($menu_options) ? $menu_options : $menu_names;
|
||||
|
||||
$form['weight'] = array(
|
||||
'#type' => 'weight',
|
||||
'#title' => t('Weight'),
|
||||
'#delta' => 50,
|
||||
'#delta' => _menu_get_menu_weight_delta($menu_options),
|
||||
'#default_value' => $item['weight'],
|
||||
'#description' => t('Optional. In the menu, the heavier links will sink and the lighter links will be positioned nearer the top.'),
|
||||
);
|
||||
|
@ -42,6 +42,39 @@ function menu_help($path, $arg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate weight's delta for a menu or group of menu options.
|
||||
*
|
||||
* @param string|array $menu_names
|
||||
* Menu name or an array of menu names to caclulate its weight's delta.
|
||||
* @param integer $max_delta
|
||||
* Optional value, delta's maximum value.
|
||||
*
|
||||
* @return int
|
||||
* Delta value for the given menu name or menu names.
|
||||
*/
|
||||
function _menu_get_menu_weight_delta($menu_names, $max_delta = NULL) {
|
||||
|
||||
if (is_string($menu_names)) {
|
||||
$menu_names = array($menu_names);
|
||||
}
|
||||
|
||||
$weight_info = db_query("SELECT MAX(weight) AS max_weight, MIN(weight) as min_weight FROM {menu_links} WHERE menu_name IN (:menu_names)", array(':menu_names' => $menu_names))->fetchObject();
|
||||
|
||||
$delta = max(abs($weight_info->min_weight), abs($weight_info->max_weight)) + 1;
|
||||
|
||||
// Honor max param, if given.
|
||||
if (!is_null($max_delta) && $delta > $max_delta) {
|
||||
$delta = $max_delta;
|
||||
}
|
||||
|
||||
// At minimum use the old hardcoded value.
|
||||
if ($delta < 50) {
|
||||
$delta = 50;
|
||||
}
|
||||
return $delta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
@ -702,10 +735,22 @@ function menu_form_node_form_alter(&$form, $form_state) {
|
||||
'#options' => $options,
|
||||
'#attributes' => array('class' => array('menu-parent-select')),
|
||||
);
|
||||
|
||||
// Get number of items in all possible parent menus so the weight selector is sized appropriately.
|
||||
$menu_names = array_keys(menu_get_menus());
|
||||
$menu_options = array();
|
||||
foreach ($menu_names as $menu_name) {
|
||||
if (isset($options[$menu_name . ':0'])) {
|
||||
$menu_options[] = $menu_name;
|
||||
}
|
||||
}
|
||||
// Make sure that we always have values in menu_options.
|
||||
$menu_options = !empty($menu_options) ? $menu_options : $menu_names;
|
||||
|
||||
$form['menu']['link']['weight'] = array(
|
||||
'#type' => 'weight',
|
||||
'#title' => t('Weight'),
|
||||
'#delta' => 50,
|
||||
'#delta' => _menu_get_menu_weight_delta($menu_options),
|
||||
'#default_value' => $link['weight'],
|
||||
'#description' => t('Menu links with smaller weights are displayed before links with larger weights.'),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user