function _menu_link_weight_get_options in Menu Link Weight 7
Same name and namespace in other branches
- 8.2 menu_link_weight.module \_menu_link_weight_get_options()
- 8 menu_link_weight.module \_menu_link_weight_get_options()
Gets a list of of options for a specific menu/parent.
Parameters
string $menu_name: The name of the menu.
int $plid: The parent link ID.
int $current_mlid: The menu link for the current item.
string $new_item_title: The title for the new menu link to be created.
Return value
array List of options with index "link_current" or the menu link ID. Values include:
- title: Santized title for the menu link.
- weight: Calculated new weight.
- db_weight: Current weight in the database, while form is being built.
See also
_menu_parents_recurse
1 call to _menu_link_weight_get_options()
- menu_link_weight_node_element_process in ./
menu_link_weight.module - Process callback for the menu link weight element.
File
- ./
menu_link_weight.module, line 270 - Replaces the menu link weight dropdown with a tabledrag widget.
Code
function _menu_link_weight_get_options($menu_name, $plid, $current_mlid, $new_item_title = NULL) {
// Get the raw tree from the database.
$tree = _menu_link_weight_get_tree($menu_name, $plid);
// Weights will have to be re-ordered from -50 to 50 for fine-grained
// control over the weight of the new element.
$weight = MENU_LINK_WEIGHT_MIN_DELTA;
$options = array();
// Find out whether to add another (fake) item for the new link.
$add_link = TRUE;
foreach ($tree as $data) {
if ($data['link']['mlid'] == $current_mlid) {
$add_link = FALSE;
}
}
// Add link on top, if needed.
if ($add_link === TRUE) {
$options['link_current'] = array(
'title' => '<strong><span class="menu-link-weight-link-current">' . truncate_utf8(check_plain($new_item_title), 30, TRUE, FALSE) . '</span></strong> (' . t('provided menu link') . ')',
'weight' => $weight,
'db_weight' => NULL,
);
$weight++;
}
// Loop through the tree again.
foreach ($tree as $data) {
// Change the title & ID for the current menu link.
if ($data['link']['mlid'] == $current_mlid) {
$id = 'link_current';
$title = '<strong><span class="menu-link-weight-link-current">' . truncate_utf8(check_plain($new_item_title), 30, TRUE, FALSE) . '</span></strong> (' . t('provided menu link') . ')';
}
else {
$id = $data['link']['mlid'];
$title = l(truncate_utf8($data['link']['link_title'], 30, TRUE, FALSE), $data['link']['link_path'], array(
'attributes' => array(
'target' => '_blank',
),
));
if ($data['link']['hidden']) {
$title .= ' (' . t('disabled') . ')';
}
}
$options[$id] = array(
'title' => $title,
'weight' => $weight,
'db_weight' => $data['link']['weight'],
);
$weight++;
}
return $options;
}