Drupal7: Jammer Module to Hide Unwanted Form Elements

David G - DrupalWhen developing websites with Drupal often times you end up with many content types. We may use content types for Staff members, News items, Events, Books, etc. Other times we may use content types for items such as Gallery Images, Messages, Header Images, Media files on a website — my point is sometimes content types can be used to hold background, or tertiary content on a website. When I have content such as this I often times try to hide un-needed form fields provided by Drupal when creating content. How ca we do this easily?

In one of my production websites I have a content type called Campus Highlights. Campus highlights contain an image of the campus for use as background decoration on sections of the site. The sections of the site are tracked using the BLAH module. By default the campus highlight type would look as follows to content managers out of the box:

Campus highlight content type with default vertical tabs: menu, path, authoring info, published, etc.

Campus highlight content type with default vertical tabs: menu, path, authoring info, published, etc.

But, I would love to be able to have content managers only see the minimum number of fields necessary to create/edit a campus highlight entry. So I’d love to have the form look like:

After applying a Jammer configurationn. Our content type shows only the fields necessary, hiding the default Drupal provided fields that are un-needed in our workflow.

After applying a Jammer configurationn. Our content type shows only the fields necessary, hiding the default Drupal provided fields that are un-needed in our workflow.

In Drupal7 you can achieve this in a custom module with PHP code that uses hook_form_alter and set the Form API #access key for the form item(s) to FALSE. This is a custom tweak to sites I’v’e done many times in the past — but this custom code gets repetitive and it’s upkeep is cumbersome. So I stumbled across the Jammer module recently. The Jammer module provides an easy to use admin interface to hide these form elements.

Once installed you can then configure per content type what items to show on the node edit form:

Jammer general configuration screen for node edit forms.

Jammer general configuration screen for node edit forms.

Actually, this form deals with most typical fields of a Node form. But not all of them. For instance I cannot hide a book field from this content type. The Jammer module has a number of submodules:

drush pml --package=jammer
 Name                                 Type    Status   Version 
 Content Form Jammer (jammer)         Module  Enabled  7.x-1.3 
 Feed Icon Jammer (jammer_feed_icon)  Module  Enabled  7.x-1.3 
 Feed Jammer (jammer_feed)            Module  Enabled  7.x-1.3 
 Generic Jammer (jammer_generic)      Module  Enabled  7.x-1.3 
 Message Jammer (jammer_messages)     Module  Enabled  7.x-1.3

These submodules let you define Jammings (?!? haha) for other forms on the site. In order to hide the book field on this form I went to the Generic Jammer admin page and entered in this content type’s $form_id and the Form API element key of the book field found within the $form array.

The Generic Jammer module hides the given element_id from any form.

The Generic Jammer module hides the given element_id from any form.

This successfully hid the book field. In doing this I did notice a small bug in the Jammer module and submitted a ticket to the issue queue, see issue #2379249.

Lastly, using Permissions you may override the setup administrative jammer configurations per Role if you need to. For this website I do not need to do this as other then the admin user there is only 1 role defined for the website and I want these Jammings applied always (the Jamming config is never applied to the admin account or uid=1).

This easy-to-use interface nicely replaces all the custom needed to do this in the past! 😀 And I’ve tried using the Configuration module to export these settings — and it was successful. This module is great — and your content editors will thank you for trimming down on the amount of inputs they complete per piece of content.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *