Tailoring Content Creation in Drupal

Drupal 7 has many powerful components to retrieve and store your custom data. Such custom data could be Car Models, News Items, Calendar Events, School Courses, a Yahoo Answers Question and Answer commentary board, a Product Showcase, etc. The core pieces of Drupal that help to define this data and the pieces that comprise them are Entities and Fields. When we make a Content Type Drupal presents the user with a generic CRUD interface generated from the FieldUI. How can we customize these types of input forms to better suite your client? How can we optimization their presentation, and interaction?

To answer these questions we can look to Drupal Core functions, and then Community Modules built to enhance core Drupal functionality.

Drupal Core Functions

Various Drupal API functions can be used in a custom programmed module to override the default behavior provided by drupal:

hook_form_alter

Perform alterations before a form is rendered.
One popular use of this hook is to add form elements to the node form. When altering a node form, the node object can be accessed at $form[‘#node’].

I often find myself denying access to certain user roles specific fields of a Form, or adjusting the ordering of items within the form:

function mymodule_form_alter() {

 global $user;

 if (in_array(‘SOME ROLE’, $user->roles)) {

   $form[‘field_SOME_FIELD’][‘#access’] = FALSE;

   $form[‘field_OTHER_FIELD’][‘#weight’] = 99;

 }

}

#after_build element and $form property

Sometimes when using the above hook_form_alter function you find that your changes aren’t visible on the page; or that the submitted values are wrong for unknown reasons. This can happen if your module’s WEIGHT causes your hook_form_alter to run before other critical modules your form depends on while being built and processed. The #after_build functions are a simple and effective way to assure your custom changes don’t interfere with built-in Drupal or Contrb module logic. For example:

// in mymodule_form_alter:

$form[‘#after_build’] = array(‘mymodule_after_build’);

function mymodule_after_build($form, &$form_state) {

 // changes to $form

 return $form;

}

Again you cause you this to alter the whole form itself, or tweak individual form elements more safely. I rarely use this function but it’s very helpful.

Drupal Community Contributed Modules

Many of these modules provide a quick, flexible means to change the presentation and interaction of content creation forms.

Arrange Fields


This module lets you drag-and-drop the fields of any CCK content type, Webform, or almost any other form in Drupal into the positions you would like for editing. This makes it super simple to have forms with inline fields, which you can change at any point. Tab indexing is also updated, so no matter how you arrange the fields, the users can still tab through them easily. And, you can now add arbitrary bits of HTML markup– labels, images, HR’s, etc.

Conditional Fields


Define dependencies between fields based on their states and values.

Conditional Fields for Drupal 7 is a user interface to the new States API, plus the ability to modify fields appearance and behavior on certain conditions when viewing content.

Field Group


Fieldgroup will, as the name implies, group fields together. All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.

Renderable Elements


Renderable elements enables you to register any forms and manage the display through an UI. It will also make (additional) elements available of existing entities on the manage forms/display screens or you can for example register the contact form and rearrange the fields through Field UI.

Display Suite


Display Suite allows you to take full control over how your content is displayed using a drag and drop interface. Arrange your nodes, views, comments, user data etc. the way you want without having to work your way through dozens of template files. A predefined list of layouts (D7 only) is available for even more drag and drop fun!

Between Drupal core functionality and trying to keep a lean and fast website — and Contrib module flexibility and customization options … there are a wealth of tools in Drupal that you can leverage to meet your exact needs.

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

Tags: , , , , | Posted under Drupal, Programming/Coding | RSS 2.0

Author Spotlight

David Gurba

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 *


7 + = 11

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>