Drupal

Posts about Drupal, the open source content management system.

Drupal Logo

Using Zend Framework In Drupal

14th August 2012 - 4 minutes read time

If you want to use Zend Framework in Drupal then most of the time you can use the Zend module. This takes a little configuration but will include the framework and instantiate the Zend_Loader_Autoloader class so that everything is ready to run.

The Zend module has a number of different strategies to including the framework, which is handy if you do or don't want to use the Libraries module. The module uses the hook_init() hook to include and instantiate the Zend_Loader_Autoloader object, which meant that this was done on every page load; even if the framework isn't being used.

Drupal Logo

EU Cookie Law Talk

15th May 2012 - 2 minutes read time

A couple of months ago I gave a talk at the North West Drupal User Group in Manchester where I talked about the EU Cookie Law and about cookies in PHP and Drupal. The EU law has been in practice in the EU for the last year and is due to be implemented in the UK on May 26th 2012.

People have been asking me to provide them with the slides so I thought I would create a quick blog post and put them on #! code.

Cookies and the EU Law.

Drupal Logo

Getting Started With Drush Make

12th May 2012 - 13 minutes read time

Drush is a command line tool that allows interaction with a Drupal site. The tool itself is incredibily useful and provides mechanisms to download modules, backup databases and most other things that can be done with Drupal. Drush Make was a plugin for Drush which has now become part of the Drush core and allows Drupal sites to be created via a make file. What Drush Make does is to use the make file to download the modules, themes and libraries needed for a Drupal site ready for the site to be installed. This means you can give this make file to another developer who can then build their own Drupal site.

Drupal Logo

Drupal7: Tip On Adding Code To Drupal Forms

7th April 2012 - 2 minutes read time

There are various different forms and modules in Drupal that allow for PHP code to be embedded into them. I have even talked about adding PHP code to forms in a previous post. These form elements can have their uses, modules like Views allow for PHP code to be run when collecting arguments which can allow for some advanced funcationality.

However, it can lead to problems. The code in the form is essentially outside of source control which means that anyone can mess about with the code and there is no way to revert changes or get back the code if the form save action failed for whatever reason.

Drupal Logo

Adding The autocomplete Attribute To Forms And Password Fields In Drupal 6

22nd February 2012 - 3 minutes read time

Many modern browsers now come with auto-complete functionality so that users can fill in their details quickly without having to type in their username and password every time they want to log on. This can be turned off by adding the attribute "autocomplete" to the form and password elements and setting its value to 'off'.

Setting the autocomplete attribute to off on password fields (and forms containing password fields) can add an added level of security to your Drupal site. This is especially important as if the computer is stolen it is more likely to contain saved passwords that will allow access to sensitive systems. So turning this feature off might be beneficial for certain systems, especially those with very sensitive information.

Drupal Logo

How To Change No Search Results Text In Drupal 6

2nd February 2012 - 2 minutes read time

Every Drupal project I finish will usually have the same request at some point. This usually happens when the client tries to do a search that produces no results and sees the search hinting text about blue smurfs.

The text about blue smurfs that is printed when there are no search results is called directly in the search module so it isn't possible to edit or override it. The solution is to use the theme_box() theme hook and override the text just before it is sent to the page. Just drop the following code into your theme.php file, rename the function to fit your theme and clear your caches.

Drupal Logo

Adding Reset Password Support To Drupal 6 Password Recovery Email

3rd January 2012 - 3 minutes read time

Drupal is capable of sending out a few different emails to users depending on different actions. The emails can be customised quite nicely with usernames, passwords, email addresses and other things by using a set of tokens. The password recovery email states that you can use the "!password" token to send the user their new password, but after a few tests I found that this token doesn't get replaced when the email is sent out.

The simplest solution here is just to remove this token from the description for this email. However, if you do want to allow user's to reset (and receive) their passwords by using this form then there are a couple of simple things you can do.

The first thing to be done is alter the user_pass form so that it uses a custom submit function that we will write. Add the following form hook to a module (or create your own for this purpose).

Drupal Logo

Adding WISIWYG Support To Drupal 7 Node Summaries

31st December 2011 - 6 minutes read time

I often get asked a simple request during a project, and the solution to the problem is sometimes more complex than I originally thought. One of these problems was adding a WYSIWYG editor to the summary field on the node edit form. There isn't an easy way to do this, but it is possible to get a good solution working.

Using the hook_form_alter() hook we can intercept and change the node edit form to change the type of the summary element from a textarea to a text_format element. In order to get the WYSIWYG component of the form working we will need to also add a format to the form element. For the purposes of this example I have created a module called wysiwyg_summary, so the hook is called wysiwyg_summary_form_alter().

Drupal Logo

Drupal 7 Expanded Menu Control On Nodes

1st December 2011 - 5 minutes read time

I recently noticed a strange little issue with Drupal 7 that seemed like either an oversight or a decision I don't agree with. Essentially, when a node is created with a menu item in place the extended flag on the menu will not be set, but the control is also not available on the menu admin page. This means that when you are trying to print out a hierarchical menu structure you need to create the page, go into the menu admin area, access the menu, click on edit to access the menu item and change the setting there.

To get around this I set about creating a little module that would add a form control to the menu options section on the node edit form. This single checkbox is used to override any settings that the menu module creates with regards to the extended menu parameter.

The first thing to do is create a simple info file for the module. I include this here for completeness.

Drupal Logo

Drupal 6 Tabledrag Forms

14th November 2011 - 16 minutes read time

A tabledrag form in Drupal 6 is any form that will allow you to move items up and down the list or into a hierarchy of items. This is actually a component of Drupal itself and is used on forms like menu, taxonomy and blocks management. Tabledrag is a great way of allowing your users to move items up and down a list with ease and they will be used to the mechanism from other areas of the site.

Essentially, a tabledrag is a normal HTML table within a form that contains some form elements and some JavaScript that will turn the table into a sortable group of elements.

I needed to create a tabledrag form in a recent project, but after not finding many good tutorials about creating a fully working form online I decided to write one. This will take you through the basics of what you need to get a weight based tabledrag form working and will also leave you with a working module.