Skip to content

Commit

Permalink
Updating menu_block to 2.6
Browse files Browse the repository at this point in the history
smithmilner committed Jun 9, 2015
1 parent bbcf556 commit 9c5b8ac
Showing 5 changed files with 71 additions and 178 deletions.
155 changes: 0 additions & 155 deletions sites/all/modules/menu_block/CHANGELOG.txt

This file was deleted.

36 changes: 22 additions & 14 deletions sites/all/modules/menu_block/menu_block.admin.inc
Original file line number Diff line number Diff line change
@@ -360,6 +360,17 @@ function menu_block_configure_form($form, &$form_state) {
),
'#description' => t('From the starting level, specify the maximum depth of the menu tree.'),
);
$form['depth_relative'] = array(
'#type' => 'checkbox',
'#title' => t('Make the maximum depth relative to the starting level while following the active menu item.'),
'#default_value' => $config['depth_relative'],
'#states' => array(
'visible' => array(
':input[name=follow]' => array('checked' => TRUE),
':input[name=depth]' => array('!value' => '0'),
),
),
);
$form['expanded'] = array(
'#type' => 'checkbox',
'#title' => t('<strong>Expand all children</strong> of this tree.'),
@@ -384,7 +395,7 @@ function menu_block_configure_form($form, &$form_state) {
$form['menu-block-wrapper-close'] = array('#markup' => '</div>');

// Set visibility of advanced options.
foreach (array('title_link', 'follow', 'follow_parent', 'expanded', 'sort', 'parent') as $key) {
foreach (array('title_link', 'follow', 'depth_relative', 'follow_parent', 'expanded', 'sort', 'parent') as $key) {
$form[$key]['#states']['visible'][':input[name=display_options]'] = array('value' => 'advanced');
}
if ($config['title_link'] || $follow || $config['expanded'] || $config['sort'] || $config['parent_mlid']) {
@@ -433,6 +444,7 @@ function _menu_block_block_save($delta = '', $edit = array()) {
variable_set("menu_block_{$delta}_level", $edit['level']);
variable_set("menu_block_{$delta}_follow", $edit['follow']);
variable_set("menu_block_{$delta}_depth", $edit['depth']);
variable_set("menu_block_{$delta}_depth_relative", $edit['depth_relative']);
variable_set("menu_block_{$delta}_expanded", $edit['expanded']);
variable_set("menu_block_{$delta}_sort", $edit['sort']);
}
@@ -509,12 +521,9 @@ function menu_block_admin_settings_form($form, &$form_state) {
'#markup' => '<p>' . t('The above list will <em>not</em> affect menu blocks that are configured to use a specific menu.') . '</p>',
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['#submit'][] = 'menu_block_admin_settings_form_submit';

return $form;
return system_settings_form($form);
}

/**
@@ -528,20 +537,19 @@ function menu_block_admin_settings_form_submit($form, &$form_state) {
$menu_order[$menu_name] = (int) $row['weight'];
}
}

// Clear menu_order before it's written to the variable table by system_settings_form_submit().
unset($form_state['values']['menu_order']);

// Sort the keys by the weight stored in the value.
asort($menu_order);
foreach ($menu_order as $menu_name => $weight) {
// Now that the array is sorted, the weight is redundant data.
$menu_order[$menu_name] = '';
}
variable_set('menu_block_menu_order', $menu_order);
if ($form_state['values']['menu_block_suppress_core']) {
variable_set('menu_block_suppress_core', 1);
}
else {
variable_del('menu_block_suppress_core');
}
drupal_set_message(t('The configuration options have been saved.'));

// Add the menu_order to the values.
$form_state['values']['menu_block_menu_order'] = $menu_order;
}

/**
6 changes: 3 additions & 3 deletions sites/all/modules/menu_block/menu_block.info
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ dependencies[] = menu (>7.11)

configure = admin/config/user-interface/menu-block

; Information added by Drupal.org packaging script on 2015-02-04
version = "7.x-2.5"
; Information added by Drupal.org packaging script on 2015-06-01
version = "7.x-2.6"
core = "7.x"
project = "menu_block"
datestamp = "1423092482"
datestamp = "1433189582"

46 changes: 43 additions & 3 deletions sites/all/modules/menu_block/menu_block.module
Original file line number Diff line number Diff line change
@@ -242,6 +242,7 @@ function menu_block_default_config() {
'level' => 1,
'follow' => 0,
'depth' => 0,
'depth_relative' => 0,
'expanded' => 0,
'sort' => 0,
);
@@ -346,7 +347,7 @@ function menu_tree_block_data(array &$config) {

if ($config['expanded'] || $config['parent_mlid']) {
// Get the full, un-pruned tree.
if ($config['parent_mlid']) {
if ($config['parent_mlid'] || $config['depth_relative']) {
$tree = menu_tree_all_data($config['menu_name']);
}
else {
@@ -356,8 +357,13 @@ function menu_tree_block_data(array &$config) {
menu_tree_add_active_path($tree);
}
else {
// Get the tree pruned for just the active trail.
$tree = menu_tree_page_data($config['menu_name'], $max_depth);
if ($config['depth_relative']) {
// Get the tree pruned for just the active trail.
$tree = menu_tree_page_data($config['menu_name']);
}
else {
$tree = menu_tree_page_data($config['menu_name'], $max_depth);
}
}

// Allow alteration of the tree and config before we begin operations on it.
@@ -372,6 +378,13 @@ function menu_tree_block_data(array &$config) {
if ($config['level'] > 1 || $config['parent_mlid']) {
if ($config['parent_mlid']) {
$parent_item = menu_link_load($config['parent_mlid']);
if (!$parent_item) {
watchdog('menu_block', "Menu block @delta is set to use parent menu link @plid but the menu link was not loadable or does not exist.", array(
'@delta' => $config['delta'],
'@plid' => $config['parent_mlid'],
), WATCHDOG_ERROR);
$parent_item = NULL;
}
menu_tree_prune_tree($tree, $config['level'], $parent_item);
}
else {
@@ -1030,3 +1043,30 @@ function menu_block_menu_order_set_menu($menu_name, $status) {
variable_set('menu_block_menu_order', $menus);
}
}

/**
* Implements hook_menu_link_insert().
*/
function menu_block_menu_link_insert($link) {
// If a book is being created, updated, or deleted, clear the
// menu_block_get_all_menus() cache since it means a change to a book "menu"
// that would need to be picked up by book_menu_block_get_menus().
if (strpos($link['menu_name'], 'book-toc-') === 0 && !$link['plid']) {
cache_clear_all('menu_block_menus:', 'cache_menu', TRUE);
drupal_static_reset('menu_block_get_all_menus');
}
}

/**
* Implements hook_menu_link_update().
*/
function menu_block_menu_link_update($link) {
menu_block_menu_link_insert($link);
}

/**
* Implements hook_menu_link_delete().
*/
function menu_block_menu_link_delete($link) {
menu_block_menu_link_insert($link);
}
6 changes: 3 additions & 3 deletions sites/all/modules/menu_block/menu_block_export.info
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ files[] = menu_block_export.admin.inc

configure = admin/config/user-interface/menu-block/export

; Information added by Drupal.org packaging script on 2015-02-04
version = "7.x-2.5"
; Information added by Drupal.org packaging script on 2015-06-01
version = "7.x-2.6"
core = "7.x"
project = "menu_block"
datestamp = "1423092482"
datestamp = "1433189582"

0 comments on commit 9c5b8ac

Please sign in to comment.