Customize "Add" node layout?

Events happening in the community are now at Drupal community events on www.drupal.org.
kpastore's picture

Does anyone know how to or have experience with customizing the 'Add' a node layout? I have the event module and want to add the ability for authenticated users to be able to add an event, however when looking at the form (yoursite.com/node/add/event if you have it installed), I wanted to remove the excess fields such as: Revision Information, Comment Settings, URL Path Settings, etc...

I'm just wondering if there is a common interface for all, or if each individual module is unique.

Thanks!

Comments

Sure deal. You should first

cmcintosh's picture

Sure deal.

You should first make sure that you have themer installed. This is where template.php is used to theme it. look up the form name and you can use the hook_alter_form to modify it. I would check out the Pro Drupal Development book. It goes into extreme depth on how to do this. or just do a search on function over ridding.

I was asking the same

melban's picture

I was asking the same question today. Thx for the info I'll try it. Also it is hook_form_alter not alter form if you had some problems finding it.

The Hook
http://api.drupal.org/api/function/hook_form_alter

Simple example on how to create a "Mini Module" for making these items not show. Note: if you are using modules like "Path" you'll need to hide them using module permissions and not using hook_form_alter().
http://drupal.org/node/325797

Thanks for the info

kpastore's picture

Thanks for the info. I'll be trying this today... and I'll let you know how it works for me. Thanks again!

Here's some code you can use

dougvann's picture

Here is some code that I sent to Kevin last week. I'm posting it here for anyone else to use,

I have a contact_us module that Brad and Aaron, 2 of my co-workers here at www.slingshotseo.com wrote before I was hired.
I decided not to start off with a whole new module, choosing rather to piggy back on this one and throw a custom function into the contact_us.module file.
I needed to remove the promote to front page and sticky check boxes from ALL forms when the user looking at them is NOT user/1 which is the GOD admin user.
Here's part of the function
// invoke hook_form_alter to unset arrays that contain buttons we don't want the non-admin users to see,
function contact_us_form_alter(&$form, $form_state, $form_id) {
// insert any additional code here that will ALWAYS be run on every page of every form. it will be called multiple times per noad load
global $user; //we must bring the $user object into scope, otherwise the test of its value will always return false. BTW: you're not a read Drupal Dev until you've [at least Twice] forgotten this and wasted a lot of time before you finally realize it!
If ($user->uid!=1) // since the $user object is in scope, we can determine who the user is. Remember that $user->uid==1 is admin and $user->uid==0 is anonymous user and every other value is some kind of authenticated user.
{
unset($form[options][promote]); // remove the "promote to front page" check box from ALL forms
unset($form[options][sticky]); // remove the sticky check box from ALL forms
}
{

OK. now, how did I know that ($form[options][sticky]) was the proper array to unset so that the sticky check box would go away? Well I went fishing. Up above in the function look at the "// insert any additional code here..." On that line, or under OR above it, enter the following
if ($user->uid==1){print_r($form);}// only admin needs to see the GIANT UGLY print out of the $form contents.
Like I mentioned above, this printout will occur a couple of times on every page load. so navigate to the form of your choice and when you get there show the code for that page CMD-U or CTRL-U on FireFox, and ALT-V then C on IE
Looking at the code do a FIND for the element that you're looking for, maybe "sticky" or "promote" or "comment" or "path"
When you find the element you want back trace it to all the way to the [options] array. This may be long [options][thisform][thatgroup][thissomething][there]
BUT when you go to enter that into the unset() function be sure to add single quotes
unset(['options']['thisform']['thatgroup']['thissomething']['there'])
Any questions, post them here. And if you're better at this than I am PLEASE tell me if there are better tools or quicker methods for getting it done. I get the job done, but I often fall short of BEST practices TEACH ME! :-)

  • Doug Vann [Drupal Trainer, Consultant, Developer]
  • Synaptic Blue Inc. [President]
  • http://dougvann.com

Isn't $user->uid == 1 the

melban's picture

Isn't $user->uid == 1 the first user created which is automatically the admin. What about sites with more than one admin? You've just locked them out too.

huh?

dougvann's picture

My script doesn't lock anyone out.
It unsets a few seldom used form elements from all node/add and node/edit forms.
But yes... $user->uid==1 IS the "God-User" that Drupal creates on a fresh Drupal install.
If you create other "admins" they are simply authenticated users who happen to have all permissions checked in thepermissions edit screen. I use the admin_role modules for that. but warning: I am convinced that there aresome things that user/1 can do that no one else can regardless of how many checks they have on their permissions screen. I'd like to know for sure.
- dv

  • Doug Vann [Drupal Trainer, Consultant, Developer]
  • Synaptic Blue Inc. [President]
  • http://dougvann.com

definitely

mikegoodwin's picture

There are definitely things that only the superuser can do (e.g. running update.php).

-Mike Goodwin
Red Leaf Media
http://www.redleafmedia.com

http://drupal.org/project/nod

neil-lyons's picture

http://drupal.org/project/nodeformcols can be used to improve the layout of the node edit form. It can also be used to hide form elements, including fieldsets, and gives control over whether a fieldset is collapsed or not etc.