Hi all,
I am new to this theme (BTW I really like it).
I just installed the theme, create my subtheme and enabled "Main Menu" under "admin/appearance/settings/mytheme". So the Main menu will be visible without setting any block.

Now I can see the Main menu, but it also shows the title "Main menu" above. I would like to hide this title, so the easiest way is to add a preprocess_page function to my subtheme and add 'element-invisible' class to the #heading variable.

The problem:
#heading variable has been set by default as a String, and my subtheme preprocess function doesn´t recognize it as an array where I can add 'class'.
Since Drupal by default will change #heading string into an array before printing it (at the end of the process), I think this variable should be treated as an array from the begining.

Please take a look at the patch, it will set this variable as an array from the begining with default settings for 'text' and 'level', so you can add 'class' or use other features.

Please review, comment... suggest, whatever!
It is my very first one patch, be kindly ;)

Comments

tuwebo’s picture

Title: How to hide $page['main_menu']['#heading'] » Change $page['main_menu']['#heading'] from a String to an Array

Hi all,
I solved it, now I can hide main_menu #heading with the 'element_invisible' class.
I have been making some research, and I found this piece of code in clean.preprocess.inc:

  // Make main and secondary menus into renderable arrays.
  $variables['page']['main_menu'] = array(
    '#theme' => 'links__system_main_menu',
    '#links' => $variables['main_menu'],
    '#attributes' => array(
      'id' => 'main-menu',
      'class' => array(
        'links',
        'inline',
        'clearfix',
      ),
    ),
    '#heading' => t('Main menu'),
  );
  $variables['page']['secondary_menu'] = array(
    '#theme' => 'links__system_secondary_menu',
    '#links' => $variables['secondary_menu'],
    '#attributes' => array(
      'id' => 'secondary-menu',
      'class' => array(
        'links',
        'inline',
        'clearfix',
      ),
    ),
    '#heading' => t('Secondary menu'),
  );

#heading is a string, so it is hard to set ['#heading']['class'] to 'element-invisible' in my theme´s preprocess function.

I have just changed (added) a couple of lines to see if it works:

  // Make main and secondary menus into renderable arrays.
  $variables['page']['main_menu'] = array(
    '#theme' => 'links__system_main_menu',
    '#links' => $variables['main_menu'],
    '#attributes' => array(
      'id' => 'main-menu',
      'class' => array(
        'links',
        'inline',
        'clearfix',
      ),
    ),
 		'#heading' => array(
    'text' => t('Main menu'),
    'level' => 'h2',
  	),
  );
  $variables['page']['secondary_menu'] = array(
    '#theme' => 'links__system_secondary_menu',
    '#links' => $variables['secondary_menu'],
    '#attributes' => array(
      'id' => 'secondary-menu',
      'class' => array(
        'links',
        'inline',
        'clearfix',
      ),
    ),
   	'#heading' => array(
    'text' => t('Secondary menu'),
    'level' => 'h2',
  	),
  );

Now I can add some code to the preprocess_page function in my subtheme.

Is this the right way? If this is the case, I will try to post a patch for it.

tuwebo’s picture

Category: support » feature
Priority: Minor » Normal
StatusFileSize
new755 bytes

I have created a patch for the clean.preprocess.inc file, modifiyng Main menu and Secondary menu's #heading from a string to an array with 'text' and 'level' values set by default.

This way, mytheme_preprocess_page function can add the class 'element-invisible' and hide the title of the menu.

Could you please take a look a it and see if it makes sense for you?
This is my first patch created, so please be advised.
Thanks.

tuwebo’s picture

Status: Active » Needs review

I have tested it, and so far it is working fine.
Have you tested it?
Changing the status to needs review.

tuwebo’s picture

StatusFileSize
new764 bytes

Sorry but there was an indenting problem in the patch. Here is the new one.
Hope it works.

tuwebo’s picture

Title: Change $page['main_menu']['#heading'] from a String to an Array » [PATCH] Change $page['main_menu']['#heading'] from a String to an Array

Changing the title. Patch added, needs review.

tuwebo’s picture

Does anyone tried the patch.
If someone did it, please report.
Thanks.

tuwebo’s picture

Category: feature » bug

Changing the status.

psynaptic’s picture

Status: Needs review » Fixed

I'm very sorry that I didn't deal with this before now. I have been a bad maintainer, very bad...

Thanks for the patch. I have committed it as-is.

http://drupalcode.org/project/clean.git/commit/d5a2f25

tuwebo’s picture

Hey psynaptic!!
Really glad to see this patch commited, thanks very much!!

psynaptic’s picture

You're welcome, thank YOU for the patch :D

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Making clear the issue summary