Commit 0d1af888 authored by davereid's avatar davereid Committed by Dave Reid

Issue #2419523 by Dave Reid: Added menu_block_delete() API and remove menu...

Issue #2419523 by Dave Reid: Added menu_block_delete() API and remove menu blocks when a menu is deleted.
parent 0d6bebbd
......@@ -140,7 +140,7 @@ function _menu_block_form_block_admin_display_form_alter(&$form, $form_state) {
/**
* Menu callback: confirm deletion of menu blocks.
*/
function menu_block_delete($form, &$form_state, $delta = 0) {
function menu_block_delete_form($form, &$form_state, $delta = 0) {
$title = _menu_block_format_title(menu_block_get_config($delta));
$form['block_title'] = array('#type' => 'hidden', '#value' => $title);
$form['delta'] = array('#type' => 'hidden', '#value' => $delta);
......@@ -151,30 +151,10 @@ function menu_block_delete($form, &$form_state, $delta = 0) {
/**
* Deletion of menu blocks.
*/
function menu_block_delete_submit($form, &$form_state) {
function menu_block_delete_form_submit($form, &$form_state) {
// Remove the menu block configuration variables.
$delta = $form_state['values']['delta'];
$block_ids = variable_get('menu_block_ids', array());
unset($block_ids[array_search($delta, $block_ids)]);
sort($block_ids);
variable_set('menu_block_ids', $block_ids);
variable_del("menu_block_{$delta}_title_link");
variable_del("menu_block_{$delta}_admin_title");
variable_del("menu_block_{$delta}_parent");
variable_del("menu_block_{$delta}_level");
variable_del("menu_block_{$delta}_follow");
variable_del("menu_block_{$delta}_depth");
variable_del("menu_block_{$delta}_expanded");
variable_del("menu_block_{$delta}_sort");
db_delete('block')
->condition('module', 'menu_block')
->condition('delta', $delta)
->execute();
db_delete('block_role')
->condition('module', 'menu_block')
->condition('delta', $delta)
->execute();
menu_block_delete($delta);
drupal_set_message(t('The block "%name" has been removed.', array('%name' => $form_state['values']['block_title'])));
cache_clear_all();
$form_state['redirect'] = 'admin/structure/block';
......
......@@ -92,6 +92,19 @@ function hook_menu_block_get_sort_menus() {
return $menus;
}
/**
* Respond to menu block deletion.
*
* @param array $config
* The menu block configuration.
*/
function hook_menu_block_delete(array $config) {
db_delete('block_data')
->condition('module', 'menu_block')
->condition('delta', $config['delta'])
->execute();
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -190,3 +190,10 @@ function menu_block_fix_custom_menus() {
function menu_block_update_7202() {
menu_block_fix_custom_menus();
}
/**
* Trigger a menu rebuild.
*/
function menu_block_update_7203() {
// Nothing needed here.
}
......@@ -77,7 +77,7 @@ function menu_block_menu() {
$items['admin/structure/block/delete-menu-block'] = array(
'title' => 'Delete menu block',
'page callback' => 'drupal_get_form',
'page arguments' => array('menu_block_delete'),
'page arguments' => array('menu_block_delete_form'),
'access callback' => 'menu_block_access',
'type' => MENU_CALLBACK,
'file' => 'menu_block.admin.inc',
......@@ -839,3 +839,75 @@ function menu_block_get_pane_links_alter(&$links, $pane, $content_type) {
}
}
}
/**
* Implements hook_menu_delete().
*/
function menu_block_menu_delete($menu) {
// Delete menu block variables.
foreach (variable_get('menu_block_ids', array()) as $delta) {
$config = menu_block_get_config($delta);
if ($config['menu_name'] === $menu['menu_name']) {
menu_block_delete($delta);
}
}
}
/**
* Delete a menu block.
*
* @param string $delta
* The delta of the menu block.
*/
function menu_block_delete($delta) {
// Since this used to be a form callback, prevent unintentional uses.
if (is_array($delta)) {
variable_set('menu_rebuild_needed', TRUE);
return;
}
$block_ids = variable_get('menu_block_ids', array());
$index = array_search($delta, $block_ids);
if ($index !== FALSE && $config = menu_block_get_config($delta)) {
module_invoke_all('menu_block_delete', $config);
// Remove the delta from the list of custom IDs.
unset($block_ids[$index]);
sort($block_ids);
variable_set('menu_block_ids', $block_ids);
// Remove all the individual variables.
variable_del("menu_block_{$delta}_title_link");
variable_del("menu_block_{$delta}_admin_title");
variable_del("menu_block_{$delta}_parent");
variable_del("menu_block_{$delta}_level");
variable_del("menu_block_{$delta}_follow");
variable_del("menu_block_{$delta}_depth");
variable_del("menu_block_{$delta}_expanded");
variable_del("menu_block_{$delta}_sort");
}
}
/**
* Implements hook_menu_block_delete() on behalf of block.module.
*/
function block_menu_block_delete(array $config) {
db_delete('block')
->condition('module', 'menu_block')
->condition('delta', $config['delta'])
->execute();
db_delete('block_role')
->condition('module', 'menu_block')
->condition('delta', $config['delta'])
->execute();
}
/**
* Implements hook_menu_block_delete() on behalf of node.module.
*/
function node_menu_block_delete(array $config) {
db_delete('block_node_type')
->condition('module', 'menu_block')
->condition('delta', $config['delta'])
->execute();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment