Tagadelic Drupal 5.0

If you aren't sure what Drupal is, you're staring at it. If you aren't sure what Tagadelic is, then look to the left of this post at the section that says Browse by category. That is the work of the Tagadelic module for Drupal. It allows you to display a list of "tags" made up of the different categories (taxonomy terms) in a category group (vocabulary). These tags are weighted so that categories with more posts in them show up in a larger, bolder font. Tagadelic made its debut two Drupal versions ago in Drupal 4.6 and has yet to be updated for version 5.0.

How in the world did I get it on my site, then, when I converted to 5.0? That is what I have been asked to tell you, and you may read on to find out if that is your question, too.

First, I downloaded the latest Tagadelic code by going to http://drupal.org/project/tagadelic and clicking on the Download latest release link. (You can also click the View other releases link to make sure that is in fact the latest release. Sometimes the current working code, called CVS, may be more up to date than the official release.) Once I extracted the files, I opened up the code file, tagadelic.module, and had a quick look.

Next, I went back to a page at Drupal.org that's been in my bookmarks for a while now, http://drupal.org/node/64279. This is a page in the Drupal handbook that details the changes from Drupal 4.7 to 5.0 that module developers need to make in their code for compatibility. For various reasons, Dries decided long ago to not support backwards compatibility. I think it's a good move, and with pages like these, it's easy for module developers or, as in my case, third party developers to take and update a module for the latest Drupal version. This can be quite a task in larger projects like e-commerce, but it's no big deal for Tagadelic.

So, what items on the list apply to Tagadelic? After browsing the code, I could see that I would need to make changes to account for items 1, 8, 12, and 23/24. If you've got the November 2, 2006 CVS version here are the line numbers for the changes:

Line 23 and 157:

theme_add_style($stylesheet, 'all');

changed to

drupal_add_css($stylesheet, 'module', 'all');

This accounts for the new way to link in stylesheets. (Item 12 on the changes list.)

Line 52:

  }

changed to

    $items[] = array(
      'title' => t('Tagadelic settings'),
      'path' => "admin/settings/tagadelic",
      'callback' => 'drupal_get_form',
      'callback arguments' => 'tagadelic_settings',
      'access' => user_access('administer taxonomy'),
      'type' => MENU_NORMAL_ITEM);
  }

Because Drupal no longer uses hook_settings, we have to define our own settings pages for modules. (Item 8 on the changes list.) This adds a menu item to Tagadelic's hook_menu function that points to the tagadelic settings page. This also uses the new way to serve up forms. Forms are displayed by using drupal_get_form() which expects to receive a form_id as its argument. (Item 23/24 on the changes list.) So this menu item displays the form defined in the function tagadelic_settings. (The form_id in Drupal 5.0 is generally the name of the function you call that builds the $form array. Item 25 on the changes list discusses an alternate way to handle form_ids, but that doesn't apply to Tagadelic.)

Line 93:

return $form;

changed to

return system_settings_form($form);

If you look back at item 8 on the changes list, you'll see mention of the system_settings_form() helper function. This adds the submit buttons to the form that we'd need for us, and it allows Drupal to handle the saving of the variables. It's very handy here!

New file, tagadelic.info:

name = Tagadelic
description = Add tagadelic browsing of taxonomy to your site.

As per item 1 on the changes list, modules now need a .info file to be recognized by Drupal. This is a wonderful new feature to Drupal that allows for module dependencies and packages while also solving a horrible problem in earlier versions referred to as the "white screen of death" on the administer >> modules page. This file needs to be created and uploaded in the tagadelic directory when you upload that to your modules directory.

So, there you have it. That's the process I used to convert the Tagadelic module. It's quite simply a matter of reading through the update list and changing those spots in the code. It helps to be familiar with the list before diving into the code you're trying to update, because you can spot things as items that need to be changed without having to flip back to the handbook too often. The major hurdle, again, is the change to the forms API. But all the other little changes can add up, too.

Something else worth noting is Drupal 5.0 and up will now use sentence capitalization for menu items, blocks, and page names. This means the first letter is capitalized and the other words are only capitalized like they would be in a sentence. This doesn't include punctuation, though. For example, the blocks on this site right now are Browse by category, Navigation, and Recent blog posts. Menu items, too, are affected, so you see items like My account, Recent posts, and Log out. In previous versions of Drupal, these things defaulted to all lower case and there wasn't an easy way to achieve this type of capitalization. With the change, you should probably adjust the titles of the menu items in the Tagadelic function tagadelic_menu to use this capitalization.

I hope this article was somewhat helpful! Feel free to comment any questions you have. Also, I encourage you to go through the changes yourself to get a feel for the updating process, but I have also attached the version of Tagadelic running on this site for you to download. If there are any problems with it, please let me know. Cool

(Once you have Tagadelic installed, you can adjust its settings from the administration menu. I won't go into all the details, but the module allows you to generate pages or blocks of content using tag clouds. I'm using the predefined block to display terms from my taxonomy vocabulary called "Category," but you'll noticed I changed the name to suit my fancy. You can do this by clicking on the Configure link on the block's row. Cheers!)

AttachmentSize
tagadelic-5.0.tar48 KB

Comments

Wise Words from Webchick

"You forgot a very important initial step, though. Smiling Always check the issue queue of the module in question to see if someone has already gone through the trouble of updating the module for you.

However, I like the fact that you've documented what you've learned in the process of updating Tagadelic, as I think that will be very helpful to new developers (and I imagine you learned some stuff in the process as well!). And now you can compare your work with Egon's to see how they match up -- it's possible you might've spotted something during the update that he didn't and vice-versa.

There is also a very important final step, which is creating a patch of your changes and submitting it to the issue queue of the module. Having a .zip of a 5.0 version of Tagadelic module on your site doesn't allow others who haven't read this post to benefit from it, and not submitting the patch for community review doesn't allow other developers to incorporate and/or improve upon your work. :)" -webchick

----------------------

(Thanks for the tips. I hope they're helpful for everyone else, too! This is normally what I do, I just spaced on the Tagadelic one since it's so small... I encourage everyone to check the issue queue, as many of the modules have already been updated. A step I would add then is to test out the already created patches you find in the issue queue to make sure nothing was missed! We're building community plumbing here. Eye-wink )

CAn do this for DrupalVB ?

I think drupalvb is a very useful modeule for integer vBulletin and drupal
would you please tell us who can change "drupalvb for drupal 4.7 " for Drupal 5.0?
thank's a lot Smiling

You know... I don't know why

You know... I don't know why I haven't got around to doing that yet. Honestly, I'll try and get it done in the near future, but I do have a vacation coming up that will keep me gone from December 22 to January 2. Maybe in the first couple of weeks of January?

Drupal 4.7 or 5

I'm just starting to look at Drupal 5 and REALLY like what I'm seeing. Unfortunately, I have to launch a site in January/February. This site will be primarily maintained by less technical grad students, so the improvements to the admin interfaces in Drupal 5 would be a HUGE help. I'm concerned that a number of modules we are planning on using haven't been updated. I've listed the modules here...

http://www.sidewalktheory.com/Drupal_4_7_or_Drupal_5

Any advice?

Tough call... personally,

Tough call... personally, I'd go with 5.0 for the admin reasons and for other performance reasons. (Useful modules are sure to be updated soon after the official release if they aren't already.) Some of those modules are rather small, and I daresay you might try your hand at module conversion. Eye-wink At least the Bio module, for example, is only a few functions and should be easily ported to 5.0. If you need some guidance, I'm happy to point the way or review your code. I am about to head out of town for about 10 days, though, so I won't really be doing much coding. I'll definitely check by here and check my email if you need any help. (Contact form.)