diff --git a/menu_block.admin.inc b/menu_block.admin.inc
index 98f3bbb..2c98b8d 100644
--- a/menu_block.admin.inc
+++ b/menu_block.admin.inc
@@ -60,6 +60,24 @@ function menu_block_add_block_form($form, &$form_state) {
}
/**
+ * Implements hook_form_FORM_ID_alter().
+ * Hides the normal block title override field since it will be replaced by one defined by menu block.
+ */
+function menu_block_form_menu_block_add_block_form_alter(&$form, &$form_state) {
+ $form['settings']['title']['#access'] = FALSE;
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ * Hides the normal block title override field since it will be replaced by one defined by menu block.
+ */
+function menu_block_form_block_admin_configure_alter(&$form, &$form_state) {
+ if ($form['module']['#value'] == 'menu_block') {
+ $form['settings']['title']['#access'] = FALSE;
+ }
+}
+
+/**
* Save the new menu block.
*/
function menu_block_add_block_form_submit($form, &$form_state) {
@@ -158,6 +176,7 @@ function menu_block_delete_submit($form, &$form_state) {
unset($block_ids[array_search($delta, $block_ids)]);
sort($block_ids);
variable_set('menu_block_ids', $block_ids);
+ variable_del("menu_block_{$delta}_menu_block_title");
variable_del("menu_block_{$delta}_title_link");
variable_del("menu_block_{$delta}_admin_title");
variable_del("menu_block_{$delta}_parent");
@@ -312,25 +331,18 @@ function menu_block_configure_form($form, &$form_state) {
'#attributes' => array('class' => array('clearfix')),
'#weight' => -19,
);
+ $form['menu_block_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Block title'),
+ '#default_value' => $config['menu_block_title'],
+ '#description' => t('Override the default title for the block. Use !placeholder to display no title, or leave blank to use the default block title.', array('!placeholder' => '<none>')),
+ );
$form['title_link'] = array(
'#type' => 'checkbox',
'#title' => t('Block title as link'),
'#default_value' => $config['title_link'],
- '#description' => t('Make the default block title a link to that menu item. An overridden block title will not be a link.'),
- '#states' => array(
- 'visible' => array(
- ':input[name=title]' => array('value' => ''),
- ),
- ),
+ '#description' => t('Make the block title a link to that menu item.'),
);
- // We need a different state if the form is in a Panel overlay.
- if (isset($form['override_title'])) {
- $form['title_link']['#states'] = array(
- 'visible' => array(
- ':input[name=override_title]' => array('checked' => FALSE),
- ),
- );
- }
$form['admin_title'] = array(
'#type' => 'textfield',
'#default_value' => $config['admin_title'],
@@ -484,6 +496,7 @@ function _menu_block_block_save($delta = '', $edit = array()) {
// Don't save values for an exported block.
$config = menu_block_get_config($delta);
if (empty($config['exported_to_code'])) {
+ variable_set("menu_block_{$delta}_menu_block_title", $edit['menu_block_title']);
variable_set("menu_block_{$delta}_title_link", $edit['title_link']);
variable_set("menu_block_{$delta}_admin_title", $edit['admin_title']);
variable_set("menu_block_{$delta}_parent", $edit['parent']);
diff --git a/menu_block.install b/menu_block.install
index 8132465..8d9fbdd 100644
--- a/menu_block.install
+++ b/menu_block.install
@@ -196,3 +196,27 @@ function menu_block_fix_custom_menus() {
function menu_block_update_7202() {
menu_block_fix_custom_menus();
}
+
+/**
+ * Converts block title overrides to menu block title overrides.
+ */
+function menu_block_update_7203() {
+ $result = db_select('block', 'b')
+ ->fields('b', array('delta', 'title'))
+ ->condition('module', 'menu_block', '=')
+ ->execute();
+
+ foreach ($result as $block) {
+ variable_set("menu_block_{$block->delta}_menu_block_title", variable_get("menu_block_{$block->delta}_menu_block_title", $block->title));
+ }
+
+ db_update('block')
+ ->fields(array(
+ 'title' => '',
+ ))
+ ->condition('module', 'menu_block', '=')
+ ->execute();
+
+ cache_clear_all();
+ return t('Menu block has been updated to store block titles');
+}
diff --git a/menu_block.module b/menu_block.module
index 45983a4..6a61c7d 100644
--- a/menu_block.module
+++ b/menu_block.module
@@ -185,6 +185,7 @@ function menu_block_get_config($delta = NULL) {
'delta' => $delta,
'menu_name' => 'main-menu',
'parent_mlid' => 0,
+ 'menu_block_title' => '',
'title_link' => 0,
'admin_title' => '',
'level' => 1,
@@ -209,6 +210,7 @@ function menu_block_get_config($delta = NULL) {
$config['exported_to_code'] = TRUE;
}
+ $config['menu_block_title'] = variable_get("menu_block_{$delta}_menu_block_title", $config['menu_block_title']);
$config['title_link'] = variable_get("menu_block_{$delta}_title_link", $config['title_link']);
$config['admin_title'] = variable_get("menu_block_{$delta}_admin_title", $config['admin_title']);
$config['level'] = variable_get("menu_block_{$delta}_level", $config['level']);
@@ -394,15 +396,26 @@ function menu_tree_build($config) {
* @param $render_title_as_link
* boolean A boolean that says whether to render the title as a link or a
* simple string.
+ * @param $config
+ * array An array of configuration options that specifies how to build the
+ * menu tree and its title.
* @return
* array A renderable array containing the tree's title.
*/
-function menu_block_get_title($render_title_as_link = TRUE) {
+function menu_block_get_title($render_title_as_link = TRUE, $config = array()) {
$menu_item = menu_block_set_title();
+ if (!empty($config['menu_block_title'])) {
+ if ($config['menu_block_title'] == '') {
+ $title_override = '';
+ }
+ else {
+ $title_override = check_plain($config['menu_block_title']);
+ }
+ }
// The tree's title is a menu title, a normal string.
if (is_string($menu_item)) {
- $title = array('#markup' => check_plain($menu_item));
+ $title = array('#markup' => isset($title_override) ? $title_override : check_plain($menu_item));
}
// The tree's title is a menu item with a link.
elseif ($render_title_as_link) {
@@ -416,14 +429,14 @@ function menu_block_get_title($render_title_as_link = TRUE) {
}
$title = array(
'#type' => 'link',
- '#title' => $menu_item['title'],
+ '#title' => isset($title_override) ? $title_override : $menu_item['title'],
'#href' => $menu_item['href'],
'#options' => $menu_item['localized_options'],
);
}
// The tree's title is a menu item.
else {
- $title = array('#markup' => check_plain($menu_item['title']));
+ $title = array('#markup' => isset($title_override) ? $title_override : check_plain($menu_item['title']));
}
return $title;
}