Drupal articles
Keep up to date with Drupal hints, tips and snippets straight from the ComputerMinds trenches ...
Ensuring a CCK field has unique values
Super quick one this: say you have a CCK field on a particular node whose values you want to ensure are unique across all nodes on your site, you could write yourself a nice little helper module, or some PHP directly into the CCK field validation section of the admin form, but, a helper module already exists!
Unique field is a lovely little module that allows you to say that a particular text, number or date field should have unique values across the site, or indeed in that node.
I used this on a user's profile node for a 'alias' field, thus ensuring that everyone chose unique aliases!
Making a drupal views block title link back to the view
One for the small but handy category this. The standard "more" link the views module adds to it's blocks has no place on a modern accessible website, you really need a more verbose link in there. One solution has always been to add a bit of footer or header text into the block, but it's a little tedious - and clients always find views hard to edit.
File uploads in Drupal 6 - Part 1
So you've got a nice new version of Drupal 6 and you're building a form, but you want to allow users to upload a file. Of course this is easy with Drupal, and we covered how to do just that, but for Drupal 5, in our previous article: Example code to build an upload form in Drupal. Here we show how file uploads are done in Drupal 6.
Organising your views in Views 1.x
If you're still stuck in the Views dark ages, and 1.6 is as good as it gets for you here's a quick tip to make things a little easier:
Using mollom with Drupal
We have recently started using Mollom on our Drupal site. Mollom is a clever anti spam service, that combines auto SPAM detection techniques with a normal CAPTCHA. The idea is simple, Mollom will check form submissions, if it thinks something is SPAM then it will prompt the submitter to complete a CAPTCHA. This means that you don't risk losing valid submissions to an over aggressive SPAM filter, and you don't risk scaring off users with an un-necessary CAPTCHA.
How to capture SugarCRM leads in Drupal
We are big fans of SugarCRM and have worked on a number of projects to integrate SugarCRM with Drupal. This is a simple guide to performing a basic data capture integration between Drupal and Sugar, using a couple of Drupal modules (webform and sugarwebform). You can see an example of this on our contact us page - feel free to fill the form in, but it is our live contact form so don't be suprised if you get a callback :)
Drupal - imagecache problems with special characters
We came across this problem on one of our Drupal sites the other day, someone uploaded an image with an ampersand in the filename, and imagecache refused to display the image. A bit of investigating revealed that imagecache had a problem with a number of special characters in the image filenames.
The solution is a little imagecache theme override - you can see examples for both Drupal5 and Drupal6 below
Remove tinymce from drupal block edit page when format is set to PHP
Small one this to compliment our other article on removing tinymce from select textareas. This enhancement will hide tinymce from the Drupal block edit screen when the input format is set to PHP. This stops the problem of tinymce stripping the PHP tags from the block edit textarea when you edit your block
The following function goes into your template.php file and will solve the problem of tinymce showing up on a block when the format is set to PHP
Displaying exposed filter form for views in Drupal 6 (views 2)
One of the joys of working with Drupal 6, and views 2, is that you have to relearn a lot of things you used to take for granted ... one trick we use in most projects is embedding views filters in blocks, nodes or custom code. There are plenty of scenarios this is useful, the classic being to create a flexible views based replacement for the normal Drupal search. Anyway, enough of the blurb - heres the good stuff - some code to give you the filter form for a Drupal 6 views 2 view.
<?php
$view = views_get_view('your_view_name');
$view->set_display('default');
$view->init_handlers();
$form_state = array(
'view' => $view,
'display' => $view->display_handler->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
);
$output = drupal_build_form('views_exposed_form', $form_state);
return $output;
?>Drupal running on lycos webhosting - 500 internal server error
Another quick one this, we recently had a small client experience issues with their Drupal site which was hosted on lycos webhosting. They hadn't changed anything on the site, but suddenly they were getting nothing but 500 (internal server) errors.
Drupal TinyMCE buttons displaying on multiple lines
A quick post about the Drupal tinymce module and it's tendancy to display all it's buttons in one inflexible line. The following CSS will split the tinymce buttons onto several lines.
Drupal mysql utf8 and latin1 character set issues
Upgrading from Drupal 4.6 has always been complicated by issues of character sets, but the Drupal upgrade scripts normally solve most of these problems for us. But when your dealing with a complex upgrade you need a good understanding of how Drupal is dealing with character sets in Mysql.
Drupal Problem with the admin/content/node page filter
A rather obscure one this, but we found a problem today on one of our Drupal sites with the filter form on the node admin screen (admin/content/node). Changing the filter settings on the form had no effect, which prevented you from filtering the list of nodes. We tracked the solution down to the $_SESSION array being cleared between page reloads, and a quick google pointed the finger at the Remember me module. Disabling the module solved the problem
Increase the performance of Drupal's ubercart for sites with a large number of products
We are in the process of putting together a large (20k products) store with ubercart and ran into some performance issues due to the hook_forms implementation.
Bulk deleting Drupal nodes of a particular content type
The Drupal admin interface allows you to delete up to 50 nodes at one time, which is great - but there are times when you it's just not enough and you need to bulk delete many thousands of nodes.
Drupal image assist force a default alt tag
We make heavy use of the Drupal image assist module (or img_assist as its known) - but find that its handling of empty alt tags is quite poor. The problem being that if when inserting the image the user does not specify a caption or description then the alt (and title) attributes are both empty.
Multilingual views in Drupal when using i18n module
Building multilingual sites in Drupal using the i18n module always throws up a few fun problems to be solved. One of the most awkward being views.
The i18n views integration module does an excellent job of allowing you to return only nodes matching a particular language, but it doesn't help when it comes to translating the view itself - and more importantly allowing a view to site nicely into multiple positions in the menu (one per language).
Drupal themeing : Adding active class to the Drupal primary links
This little snippet lives in your phptemplate_variables function and will set a useful 'active' class alongside the not so useful menuid-active class which Drupal assigns to the active primary links
<?php
foreach($vars['primary_links'] as $key=>$link){
if (strpos($key,'-active')){
$vars['primary_links'][$key]['attributes']['class']='active';
}
}
?>Drupal 5.6 bug affects prevents saving of HTML filter settings
Just flagging this as a bit of an issue - it appears there is fairly serious bug in the version of the filter module provided in Drupal 5.6 which prevents you from saving changes to the allowed HTML tags
A patch is available on drupal.org but it's quite well hidden! Post number 7 in this thread contains a working patch http://drupal.org/node/208700
An alternative solution is to download the 5.x HEAD http://drupal.org/drupal-5.x-dev) and take the version of the filter module from there
UPDATE This has now been fixed with the release of Drupal 5.7
Force the user to select a leaf item in the Drupal taxonomy
Its a tricky Drupal taxonomy problem this one, imagine you have just set up your taxonomy to represent types of web sites:
- Drupal based Sites
- Drupal based ecommerce
- Standard CMS site
- Social Networking Site
- Joomla based Sites
- Simple one page site
You set up your node type 'site', and set the vocabulary to apply to it. You create your first site and pop it into the 'Standard CMS site' category, you create another in the 'Drupal based ecommerce category'. Great. But there is a problem - there is nothing stoping you assigning your site to the 'parent' term of Drupal based Sites.


