Menu description field in node/add form | Sotak.co.uk

myself

Hi there...
My name is Marek Sotak and I am a drupal developer, consultant and designer currently based in Prague, however traveling to London quite often. :) I have more than 8 years of experience creating customized web applications for clients.

My areas of expertise include graphic design, custom websites, and Flash applications. I also specialize in Drupal, a highly customizable and robust content-management system (themes, module development). I am a co-founder of Atomic Ant ltd. Click here to contact me


Aarhus Denmark

My status twitter follow me


Popular content

calendar-icons Calendar Icons
Free calendar icons for your blog
free-mascots Free Mascots
Mascots for your web
root-candy-admin-theme Root Candy
Admin theme for drupal
drupal-profile-buttons Drupal.org buttons
Buttons to link to your d.o profile

London Drupal Developer

If you are in need of drupal developer or drupal themes get in touch with me.
Contact me

atomic ant


catch me on irc - xsign



view my drupal.org user profile
individual member - drupal
Admin templates
  • font-one
  • font-two
  • font-three

  • blog
  • services
  • portfolio
  • testimonials
  • contact

September 08th

18

Menu description field in node/add form

Submitted by sign on Tue, 09/08/2009 - 10:38.

A simple solution how to add a description field to your node/add forms.

What is that for?

We are building a website that has landing pages. Structure could be like:

  • About Us (landing page)
    • Who we are?
    • What we do?
  • Locations (landing page)
    • United Kingdom
    • Ireland

The site structure is based on a menu, thus each page has its menu and most importantly parent menu item if it is not landing page. When visitor is viewing a landing page, the page consists of a text from landing page node and a list of first level sub-menu items with its description (views can't do this afaik).

Here is the landing page layout:

landing page

The only problem is, that in node/add form menu fieldset doesn't have description field. So user adding or editing a new content has to after content creation visit menu administration, select the menu item and edit description. Not a good workflow eh? :)

So first we need to use form_alter to add a description field to a menu fieldset:

<?php
/**
* Implementation of hook_form_alter(). Adds menu item fields to the node form.
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if (isset(
$form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
   
$form['menu']['description'] = array(
     
'#type' => 'textarea',
     
'#title' => t('Description'),
     
'#default_value' => isset($form['menu']['options']['#value']['attributes']['title']) ? $form['menu']['options']['#value']['attributes']['title'] : '',
     
'#rows' => 1,
     
'#description' => t('The description displayed when hovering over a menu item.'),
    );
   
$form['#submit'][] = 'mymodule_node_form_submit';
  }
}
?>

then, as you can see in the code above, we have our own form submit callback. Let's add that too:

<?php
function mymodule_node_form_submit($form, &$form_state) {
 
$form_state['values']['menu']['customized'] = TRUE;
 
$form_state['values']['menu']['options']['attributes']['title'] = $form_state['values']['menu']['description'];
}
?>

And that's it. Now in node/add form we have in menu fieldset a description field too. :)

  • 4337 reads
  • Delicious Delicious
  • Technorati Technorati
  • drupal
  • drupal 6.x
  • form API
  • planetdrupal

Comments

Wed, 09/09/2009 - 06:48 — dalin (not verified)

teasers

I can't quite understand how those aren't just teasers.

  • reply
Wed, 09/09/2009 - 07:28 — sign

good question

as written in the post, the site structure is defined by menu system. so what we want to get below each landing page is a sub-level items based on parent menu.

in case of teasers, we will need to:
(custom code)
get the menu structure
get the nodes and output teasers

with just menus and using description field:
(custom code)
get the menu structure

most importantly we wanted to keep that menu item description there, in case ppl hover over it in the menu
and one more thing, teasers and menu description unfortunately arent same in our case, teaser is being used somewhere else

  • reply
Wed, 09/09/2009 - 10:54 — sign

forgot the main issue, the

forgot the main issue, the sub pages doesn't have to be nodes! so it could be views for example.

  • reply
Wed, 09/16/2009 - 15:42 — kamagra (not verified)

Yep, this is confusing me :/

Yep, this is confusing me :/

  • reply
Wed, 09/16/2009 - 20:34 — Anonymous (not verified)

Thanks for saving me an hour of coding!

Had this exact need on a site using UTF-8 multilingual strings for menu titles, but English translation for the tooltip (menu description field). By default, Drupal was nulling the descriptions set in the menu admin when a node was saved. Not nice.

Thanks again for allowing me to copy-paste instead of trying to find all the form keys!

  • reply
Wed, 11/11/2009 - 15:10 — alcohol rehab (not verified)

help with drupal is

help with drupal is gr6...thanks..eep postign and helping others...

  • reply
Mon, 03/01/2010 - 18:37 — Anonymous (not verified)

I think you should

I think you should definitely have landing pages on your websites. This really explains what you are all about.
palm beach cosmetic dentist

  • reply
Wed, 03/03/2010 - 18:03 — marlie marie Soro (not verified)

Hello, possibly you could

Hello, possibly you could assist me? I see u are using drupal on your web site. I recently decided to create a blog for myself and i am presently using one of the free blog website services that are in my country, but i would really like to make my own blog using my private site name. I did recently read about blog engine and i was thinking maybe you might know where i may be able to find good training or videos on how to make use of drupal properly? Thanks!

  • reply
Thu, 03/04/2010 - 09:02 — emma r. (not verified)

hi

Buy viagra

  • reply
Thu, 03/04/2010 - 10:39 — Anonymous (not verified)

The problem of comment

The problem of comment quality — and you have increased blog traffic and interaction as well. You also draw more attention to your reviews, because people would naturally want to read about what they can win. Good stuff. This will for sure increase your visitors to your blog!
meilleur site de roulette

  • reply
Sat, 03/06/2010 - 16:52 — Rakesh (not verified)

Custom imprinted promotional

Custom imprinted promotional computer bags, Promotional Tote Bags, promotional backpacks; messenger bags also make great promotional giveaways. Hand them out promotional bags to select prospective clients or raffle them off at your next computer expo or career fair. Visitors can use handy promotional tote bags containing your imprinted company logo embroidered to carry their Promotional Products,Promotional knives

  • reply
Sat, 03/06/2010 - 17:17 — Anonymous (not verified)

sigarayı bırakma çayı -

sigarayı bırakma çayı - sigarayı bırakma yöntemleri - sigaranın zararları - nikotinsiz sigara bırakma - sigara bırakma - sigarayı bırakma - sigarayı bırakmak için - sigarayı bırakma yolları - sigara bırakmanın yolları - en etkili sigara bırakma yöntemi - sigarayı bırakmanın yolları bitkisel

  • reply
Mon, 03/08/2010 - 05:42 — Tony (not verified)

Very funny article writing

Very funny article writing about who we are and for what we are about.
golf tee times
discount tee times
online tee times

  • reply
Mon, 03/08/2010 - 08:21 — Anonymous (not verified)

csdacsd

Unterkunft in Prag

  • reply
Tue, 03/09/2010 - 06:25 — creativecards (not verified)

Vietnam Travel, Vietnam

Vietnam Travel, Vietnam Tour, Vietnam Hotel, Vietnam Opentour - Vietnam Open Tour provides tourist services in Vietnam. Our market is from budget traveler who have a chance to join daily typical tours with others, to traveler who wants a customized tours, personalized service and a high quality product, who want to go where they want to go, do what they want to do and have the travel experience they desire. We care about every person and every tour we do. We try our best for you. This is who we are. This is what we have been doing since 1998.

  • reply
Tue, 03/09/2010 - 09:07 — Cliff (not verified)

Webthesurfi Rugs Webdesign

Webthesurfi Rugs Webdesign

  • reply
Tue, 03/09/2010 - 09:10 — Jamella (not verified)

UK Essays right here and

UK Essays right here and there.

  • reply
Tue, 03/09/2010 - 09:48 — wltwtkpwtkp (not verified)

xanax Australia ambien

xanax Australia
ambien Australia
ativan australia
levitra Australia
phentermine australia
tramadol australia
tadalafil Australia
Diazepam in Australia
viagra in Australia

  • reply

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.