July Meeting - TC Posse Takes Over

Events happening in the community are now at Drupal community events on www.drupal.org.
samirnassar-gdo's picture
Start: 
2008-07-23 19:00 - 21:00 US/Central
Event type: 
User group meeting

The July Twin Cities Drupal Group meeting will be a special event. The meeting will consist of short lightning presentations instead of the long presentation format.

Over the next few weeks Twin Cities Drupal users will be attempting a "see one, do one, teach one" approach to teaching each other about Drupal.

What does this mean?

See one

Figure out what you want to learn about. Building themes? Fixing bugs? Got a module stuck on Drupal 5? Hopefully somebody will teach you.

Do one

When you know more about how to approach a problem, find others who have the same problem and collaborate.

Teach one

When you see a question asked about Drupal you know the answer to, teach someone. You will be continuously surprised by how much you know and by your capacity to teach others.

Where are people figuring all this out? On the TC Posse wiki!

See, Do, Teach Deliverables:

  • Lightning presentations for July group meeting
  • Bugs fixed to be submitted to modules and core
  • Better understanding of Drupal code
  • Building a stronger Drupal ecosystem
  • Fun!

Comments

Meeting tomorrow!

allie micka's picture

Summertime flies when you're having fun! This meeting is scheduled for tomorrow night!

We're doing lightning talks, which means that each of us is spending 5 minutes going over a tool, module, hack, or programming tip. If you're not up to giving a presentation, we're looking for scribes: each talk needs a volunteer to write it up as it happens!

For those of you not actively following the wiki updates, the currently suggested presentations are here:

  • Turning designs into Zen sub-themes - Samir M. Nassar (SteamedPenguin)
  • Beginning Drupal Hacking with Bazaar - Kyle Cunningham (CitizenKane)
  • Using patch and diff: Becoming a patch tester for modules and core - Samir M. Nassar (SteamedPenguin)
  • Using patch and diff: You found a bug! Now fix it. -Samir M. Nassar (SteamedPenguin)
  • Using the coder module - Samir M. Nassar (SteamedPenguin)
  • Custom cosmetic tweaks you can do with APIs when theming doesn't cut it, starring hook_form_alter(). - Gabe Ormsby (gormsby)

There's room for a few more presentations, and plenty of room for people willing to act as a scribe ( writing up a presentation as it happens ) If nobody objects, perhaps we can use the comments here to volunteer for presentations so that they go out to the email subscribers.

Yikes! Time does indeed fly...

dgorton's picture

I'll be a scribe tonight for anyone who doesn't have one already. I'll also try to put something relevant together for a presentation...

Drew Gorton
Gorton Studios

Sorry

maher's picture

Sorry guys i wont be able to make it. I will be leaving over seas in a couple of days for about 3 weeks and just busy getting things together.

Sorry again.

Sorry +1

nihiliad's picture

I won't be able to make it, either. Hopefully next time for sure!

dgorton's picture

Situation - You need to override a core (or contrib) module's behavior. More specifically, we want to adjust a form in some way. It would be possible to edit the files you want, but that's BAD Drupal development. We want to do make changes without killing our chance to benefit from future versions of those modules.

Tool: hook_form_alter()

"Before building [a] form, the form_alter() hook is called. Any module that implements the form_alter() hook can modify anything in the form. This is the primary way to change, override, and munge forms that are created by modules other than your own."
- Pro Drupal Development, John VanDyk and Matt Westgate

So, we're going to write a very simple example module to do just this. Some good resources for creating modules:
Drupal 5.x - http://drupal.org/node/82920
Drupal 6.x - http://drupal.org/node/206753
NOTE: This is a Drupal 5 example.

In this example, "nsa" is indicative of the "Narrow Sidebar Alliance" module - our theoretical client whose site we're customizing. Our module contains one function:

<?php
function nsa_form_alter($form_id, &$form) {
 
// only tweak the sidebar blocks
 
if ($form_id == 'search_block_form') {
   
$form['search_block_form_keys']['#size'] = 8;
  };
 
  if (
$form_id == 'user_login_block') {
   
$form['pass']['#size'] = 8;
   
$form['name']['#size'] = 8;
  };
}
?>

By enabling this module, Drupal will ask it for feedback any time a any form is presented to the screen. This is the magic of hook_form_alter in general and illustrative of Drupal's overall coolness in general.

The function nsa_hook_form_alter looks at the name of the form ($form_id) being presented to see if it is one of the forms we want to change.

<?php
 
if ($form_id == ...
?>

A quick review of the user.module and search.module tells us the names of the forms we want to affect: the search block form ("search_block_form") or user login form ("user_login_block"). Per Gabe's notes:

Identifying your form id and its form elements

Lucky case: Take "id" of HTML form element as the form id, try the form field names as sub-arrays, and try the field attributes as keys for the sub-arrays, change "-" to "_", and see if you win:

In our module, is successfully targeted using "search_block_form" as the Drupal id, "name" and "pass" as array keys for the elements, and "#size" for the size attribute.

Unlucky case: You may have to dig through the module code:
In our module, the actually has "user_login_block" as the Drupal id.

If the $form_id is either of those two:

<?php
 
// only tweak the sidebar blocks
 
if ($form_id == 'search_block_form') {
...
  if (
$form_id == 'user_login_block') {
?>

... then we want to make some changes, specifically changing the width of the text boxes people type in:

<?php
    $form
['search_block_form_keys']['#size'] = 8;
...
   
$form['pass']['#size'] = 8;
   
$form['name']['#size'] = 8;
?>

... at the end of it all, our new version of the form is handed back to Drupal for more magic, until eventually it shows to the user.

Thanks Gabe!

Drew Gorton
Gorton Studios

Twin Cities

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week