After porting my theme to the latest version of zen 7.x-3.x I got this Notice every page:

Notice: Undefined index: in zen_preprocess_page() (line 227 of /local/drupal-7/sites/all/themes/zen/template.php).

The functions code is this, the last line is 227

function zen_preprocess_page(&$variables, $hook) {
// Find the title of the menu used by the secondary links.
$secondary_links = variable_get('menu_secondary_links_source', 'user-menu');
$menus = menu_get_menus();
$variables['secondary_menu_heading'] = $menus[$secondary_links];
}

I found out, that the error only occurs, when I disable the secondary menu under Structure>Menus>Settings
If you can reproduce it, I think this is a major issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Foxhaven’s picture

I had the same issue (Secondary menu turned off, "Rebuild theme registry on every page" turned off). Tried re-enabling secondary menu, still had warning.

Turned on "Rebuild theme registry on every page", got rid of warning.
Turned rebuild registry off, no warning.
Cleared cache, turned secondary off & on and fiddled with performance settings... no warning.

In fact, after rebuilding the theme registry that once (with the Mar 2nd 7.x-3.x-dev) I have not been able to duplicate this issue.

My take on it is that the theme registry set from the previous 7.x-3.x-dev didn't like whatever changes came down on Mar 2nd.

Try clearing the cache and rebuilding the registry and let us know if you still get that warning.

Crossfeed’s picture

In my zen sub-theme "rebuild registry on every page" is enabled. Now I tried cleaning the cache but still got that warning.
This error also occurs when I activate the Zen base theme.

komal.savla’s picture

Hi,

I was able to reproduce the same isssue on my local site.
And it seems like when we disable the secondary links, $secondary_menu_heading is not set/is empty , so the warning of Undefined index comes up.
I added the following if statements in my template.php and page.tpl.php and it worked for me.
Now I dont get any warning message.

Following are the changes that i have made:

In zen/template.php on line no 227

 if(!empty($secondary_links)) {
  $variables['secondary_menu_heading'] = $menus[$secondary_links];
}

And in page.tpl.php

<?php if(!empty($secondary_menu_heading)): ?>  // Added this line
   <?php print theme('links__system_secondary_menu', array(
      'links' => $secondary_menu,
      'attributes' => array(
        'id' => 'secondary-menu',
        'class' => array('links', 'clearfix'),
      ),
      'heading' => array(
        'text' => $secondary_menu_heading,
        'level' => 'h2',
        'class' => array('element-invisible'),
      ),
    )); ?>
<?php endif; ?> // Added this line
Crossfeed’s picture

This fixes the issue.
I am at the very beginning of Git migration and failed to make a patch out of it. I will continue and try later.
If someone is quicker he can also patch this.

Crossfeed’s picture

Status: Active » Needs review
FileSize
1.45 KB

Finally got it, but I was not able to push the changes to origin

komal.savla’s picture

Hi,

I came across this issue http://drupal.org/node/1085790 . The issue mentioned on this link is similar to this issue.
So the code which i have mentioned above i.e #3 has to be modified a bit so that both the issues are solved.

Here is the code that has to be modified in template.php

if(!empty($secondary_links)) {     // Moved if statement above $menus = menu_get_menus();
  $menus = menu_get_menus(); 
  $variables['secondary_menu_heading'] = $menus[$secondary_links];
}
Crossfeed’s picture

Version: 7.x-3.x-dev » 7.x-5.x-dev
FileSize
2.31 KB

Just modified the patch to match your code

essbee’s picture

Patch worked for me.

Jens Peter’s picture

Version: 7.x-5.x-dev » 7.x-3.x-dev

I have attached the patch and still have the error. I have tried flush the cash, mark second menu as active and not active, rebuild and not rebuild... and no matter what I do, I get the same error...

Notice: Undefined index: menu-submenu in zen_preprocess_page() (line 228 of /var/www/www.domain.com/www/sites/all/themes/zen/template.php).

Please help.
I even tried to replace the ZEN with the older version but that didn't help as it was like Drupel already had seen the new version. I don't know how to uninstall the ZEN theme to correctly replace it with the older, working version.

Crossfeed’s picture

For deinstallation, you have to deactivate the Theme and set a standard theme as default. Then you might delete the Zen folder in sites/all/themes/

I just installed a clean drupal7 with Zen (Starterkit Theme) and the latest patch from above. I don't get any trouble with this issue, patch works.

MustangGB’s picture

Fatal error: Call to undefined function menu_get_menus() will still occur if the core Menu module is disabled
I guess you would need to do it like this

function zen_preprocess_page(&$variables, $hook) {
  // Find the title of the menu used by the secondary links.
  $secondary_links = variable_get('menu_secondary_links_source', 'user-menu');
  if(function_exists('menu_get_menus') && !empty($secondary_links)) {  
    $menus = menu_get_menus();
    $variables['secondary_menu_heading'] = $menus[$secondary_links];
  }
}
Crossfeed’s picture

In my case, I don't get this error when I disable menu.module and use the (patched 7.x-5.x) Zen (Starterkit) on a clean d7 installation

Crossfeed’s picture

disregard, tried some times, now I get it to. I will try to roll a patch for this

Crossfeed’s picture

FileSize
1.54 KB

Code above wrapped in a patch

Anonymous’s picture

Can someone tell me if this patch is to be applied to the template.php of your zen theme? That's not working for me.

JohnAlbin’s picture

Title: PHP Error when secondary Menu is disabled » PHP Error when secondary menu or menu module is disabled
Status: Needs review » Fixed
FileSize
735 bytes

The if statement in the page.tpl is unnecessary if we ensure that $secondary_menu_heading gets a value in zen_preprocess_page().

Also, the current patch doesn't quite work if the menu module is disabled while the secondary menu is enabled. The heading for the secondary menu is empty instead of containing the menu's title.

Here's the patch I committed.

Thanks for all your help, everyone! You're in the CHANGELOG now.

Fixed. http://drupalcode.org/project/zen.git/commit/9d330c3

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

UksusoFF’s picture

Version: 7.x-3.x-dev » 7.x-5.5
Component: PHP code » PHP/JS code
Issue summary: View changes

Same trouble:
Notice: Undefined index: menu-afisha in zen_preprocess_page() (line 257 of .../sites/all/themes/zen/template.php).

UksusoFF’s picture

Status: Closed (fixed) » Active
JohnAlbin’s picture

Version: 7.x-5.5 » 7.x-5.x-dev
Status: Active » Fixed

I've added an isset(). Fixed!

  • JohnAlbin committed 4fad3f2 on 7.x-5.x
    Issue #1084504: PHP Error when secondary menu or menu module is disabled
    

  • JohnAlbin committed 258791d on
    Issue #1084504: PHP Error when secondary menu or menu module is disabled
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.