Instantly share code, notes, and snippets.
Created
March 11, 2014 11:08
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save mikl/9483722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/menu_block.admin.inc b/menu_block.admin.inc | |
index 98f3bbb..143ed9a 100644 | |
--- menu_block.admin.inc | |
+++ menu_block.admin.inc | |
@@ -423,7 +423,7 @@ function menu_block_configure_form($form, &$form_state) { | |
'#default_value' => $config['sort'], | |
'#description' => t('Sort each item in the active trail to the top of its level. When used on a deep or wide menu tree, the active menu item’s children will be easier to see when the page is reloaded.'), | |
); | |
- $form['parent_mlid'] = array( | |
+ $form['parent'] = array( | |
'#type' => 'select', | |
'#title' => t('Fixed parent item'), | |
'#default_value' => $config['menu_name'] . ':' . $config['parent_mlid'], | |
@@ -432,11 +432,11 @@ function menu_block_configure_form($form, &$form_state) { | |
'#attributes' => array('class' => array('menu-block-parent-mlid')), | |
'#element_validate' => array('menu_block_configure_form_parent_validate'), | |
); | |
- $form['parent_mlid']['#options'][MENU_TREE__CURRENT_PAGE_MENU . ':0'] = '<' . t('the menu selected by the page') . '>'; | |
+ $form['parent']['#options'][MENU_TREE__CURRENT_PAGE_MENU . ':0'] = '<' . t('the menu selected by the page') . '>'; | |
$form['menu-block-wrapper-close'] = array('#markup' => '</div>'); | |
// Set visibility of advanced options. | |
- foreach (array('title_link', 'follow', 'follow_parent', 'expanded', 'sort', 'parent_mlid') as $key) { | |
+ foreach (array('title_link', 'follow', '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']) { | |
@@ -451,18 +451,13 @@ function menu_block_configure_form($form, &$form_state) { | |
*/ | |
function menu_block_configure_form_parent_validate($element, &$form_state) { | |
// Determine the fixed parent item's menu and mlid. | |
- list($menu_name, $parent_mlid) = explode(':', $form_state['values']['parent_mlid']); | |
+ list($menu_name, $parent_mlid) = explode(':', $form_state['values']['parent']); | |
+ $form_state['values']['parent_mlid'] = (int) $parent_mlid; | |
+ | |
if ($parent_mlid) { | |
// If mlid is set, its menu overrides the menu_name option. | |
$form_state['values']['menu_name'] = $menu_name; | |
} | |
- else { | |
- // Otherwise the menu_name overrides the parent item option. | |
- $form_state['values']['parent_mlid'] = $menu_name . ':0'; | |
- } | |
- // The value of "parent" stored in the database/config array is the menu name | |
- // combined with the optional parent menu item's mlid. | |
- $form_state['values']['parent'] = $form_state['values']['parent_mlid']; | |
} | |
/** | |
diff --git a/menu_block.module b/menu_block.module | |
index 5366a1b..006e4b1 100644 | |
--- menu_block.module | |
+++ menu_block.module | |
@@ -185,6 +185,7 @@ function menu_block_get_config($delta = NULL) { | |
'delta' => $delta, | |
'menu_name' => 'main-menu', | |
'parent_mlid' => 0, | |
+ 'parent' => '', | |
'title_link' => 0, | |
'admin_title' => '', | |
'level' => 1, | |
@@ -216,7 +217,8 @@ function menu_block_get_config($delta = NULL) { | |
$config['depth'] = variable_get("menu_block_{$delta}_depth", $config['depth']); | |
$config['expanded'] = variable_get("menu_block_{$delta}_expanded", $config['expanded']); | |
$config['sort'] = variable_get("menu_block_{$delta}_sort", $config['sort']); | |
- list($config['menu_name'], $config['parent_mlid']) = explode(':', variable_get("menu_block_{$delta}_parent", $config['menu_name'] . ':' . $config['parent_mlid'])); | |
+ $config['parent'] = variable_get("menu_block_{$delta}_parent", $config['menu_name'] . ':' . $config['parent_mlid']); | |
+ list($config['menu_name'], $config['parent_mlid']) = explode(':', $config['parent']); | |
} | |
return $config; | |
diff --git a/plugins/content_types/menu_tree/menu_tree.inc b/plugins/content_types/menu_tree/menu_tree.inc | |
index 024846a..1b75582 100644 | |
--- plugins/content_types/menu_tree/menu_tree.inc | |
+++ plugins/content_types/menu_tree/menu_tree.inc | |
@@ -111,13 +111,13 @@ function menu_block_menu_tree_content_type_edit_form($form, &$form_state) { | |
// Set the options to a simple list of menu links for the configured menu. | |
$menus = menu_block_get_all_menus(); | |
- $form['parent_mlid']['#options'] = menu_parent_options(array($conf['menu_name'] => $menus[$conf['menu_name']]), array('mlid' => 0)); | |
+ $form['parent']['#options'] = menu_parent_options(array($conf['menu_name'] => $menus[$conf['menu_name']]), array('mlid' => 0)); | |
// Hide the Parent item option for the special "active" menu. | |
if ($conf['menu_name'] == MENU_TREE__CURRENT_PAGE_MENU) { | |
- $form['parent_mlid']['#type'] = 'hidden'; | |
+ $form['parent']['#type'] = 'hidden'; | |
} | |
// Remove CSS class hooks for jQuery script on parent select. | |
- unset($form['parent_mlid']['#attributes']); | |
+ unset($form['parent']['#attributes']); | |
return $form; | |
} | |
@@ -127,9 +127,7 @@ function menu_block_menu_tree_content_type_edit_form($form, &$form_state) { | |
*/ | |
function menu_block_menu_tree_content_type_edit_form_submit(&$form, &$form_state) { | |
foreach (array_keys($form_state['subtype']['defaults']) as $key) { | |
- if (!empty($form_state['values'][$key])) { | |
- $form_state['conf'][$key] = $form_state['values'][$key]; | |
- } | |
+ $form_state['conf'][$key] = $form_state['values'][$key]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment