Drupal articles
Keep up to date with Drupal hints, tips and snippets straight from the ComputerMinds trenches ...
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
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.
Query string in drupal menu items
This was written in response to a post on drupal.org regarding query strings in drupal menu items. Currently if you create a drupal menu item linking to an external site with a querystring then this will render correctly. However if you try and use a relative URL (i.e. an internal link) then your querystring will be escaped and the URL won't work.
This override lives in your template.php file and parses all your menu paths for internal links, and will pass query strings into the l function correctly ...
Remove the image assist icon from Drupal textareas
This small theme override will allow you to select which Drupal textareas the image assist icon will appear on
/**
* Theme for adding an image link underneath textareas
*/
function phptemplate_img_assist_textarea_link($element, $link) {
if ($element['#id']=='edit-body'){
return theme_img_assist_textarea_link($element, $link);
}
}
The above code will limit the icon to appearing on only the node edit body fields, you can add more ids as required
Mod rewrite rules and querystring parameters in Drupal
Just a quick one this, and not strictly Drupal related - but might save you some time when you are writing modrewrite rules to rewrite legacy URLs.
The problem : We had a whole bunch of legacy URLs in the format index.php?Page=SomePageHere which we needed to rewrite to point at some shiny new Drupal URLs.
Allowing HTML in Drupal menu items
You have to be a little careful with this one, but there are many times when in would be very handy to have HTML in your Drupal menu items. For example, you might want your Drupal menu to have a <br> to force a break, or perhaps insert a <span> around some content to get a two-tone menu item
Add the following to your Drupal theme's template.php file
function phptemplate_menu_item_link($item, $link_item) {
$output = l($item['title'],
$link_item['path'],
array(),
null,
null,
false,
true);
}
By setting the final paramater on the l function to true, we are telling Drupal that the menu item should be treated as HTML. NOTE this obviously means all your menu items will now not be filtered, so probably best not to use this on a site where punters can add menu items!
Customising the Drupal search block form
The Drupal search block form is one of those things that gets used in most themes, and frequently needs a bit of themeing to bring it in line with your target design.
The following snippet (which needs to live in your template.php file) will change the word "Search" in the submit button to "Go", and will add a title to the search terms box ...
function phptemplate_search_block_form($form) {
$form['search_block_form_keys']['#title']='search the site';
$form['search_block_form_keys']['#size']=10;
$form['submit']['#value']='GO!';
return drupal_render($form);
}
Allowing unfiltered content on the Drupal contact page
The contact page exposed by the Drupal contact module is great, it allows you to put together a contact form quickly and easily. But there is one small(ish) problem, the header text for the form is being filtered - which prevents you from using certain tags (for example embed). We found this problem when trying to embed a youtube movie onto the drupal contact form.
The solution is a little bit of themeing - put the following in your template.php file, you will have to be a bit carefull as your now not filtering your output - so you HAVE to be able to trust the person editing the contact form details.
Drupal - Fatal error : allowed memory size exhuasted
One of the classic Drupal problems that catches a lot of newbies out is the memory error exhausted error. Typically you get this on the modules page - but it could appear almost anywhere.
Its nothing much to worry about and can be easily solved by following the advice posted here http://drupal.org/node/76156
Flash objects in Drupal
Its always the way, you go months without dealing with flash in Drupal when all of a sudden you get 5 people all asking the same thing, how do you deal with flash in Drupal.
We use the swftools module (http://drupal.org/project/swftools), these excellent modules give you an easy way to embed flash objects in your Drupal site. We will cover the basics of adding flash content to your Drupal site below.
Fix Drupal fieldset titles disappearing in firefox
You may have spotted that for some Drupal themes in some versions of Firefox the titles on fieldsets are sometimes not there ...
This little CSS snippet should solve the problem ...
fieldset legend {display:block; }
Adding text to the Drupal feed icon
Drupal's handling of RSS's feeds is generall excellent, BUT sometimes it's nice to add a bit of explanation text to the standard orange feed icon.
Adding custom markup to Drupal menu items
There are times when it's necessary to add some additional markup to a particular menu item, for example a link to DrupalMinds might need a strong tag around the Drupal portion.
This can be achieved in a couple of ways, both using a very similar theme override.
Drupal redirect after logout
A quick one that came up today, we all know about the login redirect module, which automatically redirects the user to a specific page when they login ... but what about at logout?
Drupal - changing the calander view to display single letter for day of the week
By default the Drupal event module will provide a nice calander block, listing the days of the week accross the top using 3 letter abbreviations (mon, tue etc).
Removing tinymce from textareas
TinyMCE has a habit of popping up right where you don't want it - the log field on a node edit page is a good example.
Adding an active class to the Drupal primary links
One of the most annoying things about developing a Drupal theme is the lack of an 'active' class on your primary links. By default the primary links are given a class of menu-X-Y-Z-active if they are active. From a theming point of view, this is next to useless, you need a nice standalone active class on your primary links.
Tinymce width problems - CSS snippet
We have had a few sites recently on which TinyMCE was playing up on narrow themes. The buttons where not breaking onto new lines, causing the TinyMCE textarea to be much too wide.
Adding new regions
Adding new custom regions (areas into which you can place blocks) to a Drupal template is dead easy ...
Drupal 5.2 released
Drupal 5.2 was released last night, containing a couple of quite importants ecurity patches and some other minor bug fixes.
We will be upgrading our client's sites over the next couple of days
Tinymce and filtered HTML
Just a quick one this - you will probably find that when you use Tinymce and the standard Filtered HTML input format, all your text bunches up and doesn't break correctly.
Once solution to this is to use Full HTML - fine for the admin user but not so good for your average member of the great unwashed.
So, the solution is to goto admin/settings/filters and configure the "filtered HTML" filter. You then want to add <p> and <br> to the list of allowed tags.
Everything should now be lovely!
Modifying the Drupal local tasks to include the destination
There is nothing worse than having your browsing flow interrupted by a login screen that does not return you to your origional destination. Drupal manages to get around this problem by allowing you to append a "destination=XXX" query string parameter to the 'user' login URL.
This is excellent and works well, except what happens if the user clicks the register tab while on the login screen - the destination query string is lost and the user has to resort to the back button.
This little snippet attempts to solve this problem - stick it into your template.php file, it very simply just adds the destination query string to each of the local tasks.
It is completley untested so use at your own risk!!
Getting the drupal captcha module to work
This article applies to the current dev release of both the captcha and the textimage module. It involves modifying captcha.inc file which is distributed with the textimage module - it is therefore only a temporary solution and should be treated with caution!
Example code to build an upload form in Drupal
Putting together an upload form in Drupal 5 is easier than you think - there are just a couple of things you need to remember ...
Our top tools for developing and debugging with Drupal
It is perfectly possibly to work with Drupal using the free tools that come with Windows, nothing more than notepad and Internet Explorer - but just because its possible doesn't mean its a good idea!
We work with Drupal all day everyday - and rely on a small arsenal of applications to stop us going insane!
Issues with getting TinyMCE to work in Drupal 5
I'll keep this one nice and short - and hopefully save a couple of people participating in a bit of self inflicted baldness!
Installing the TinyMCE module (a nice WYSIWYG editor) in Drupal 5 should be a breeze.
Basically you copy the module into your modules directory. Then hit the TinyMCE site and download the latest version of the TinyMCE javascript/images - which you put into the tinymce directory in your modules directory.
You then enable the module as you would any other.
You now need to ensure you have at least 1 role created - AND ensure that the admin user is a member of this role (if you intend for them to use the tinymce editor).
You will then need to goto admin/settings/tinymce and create a "new profile", ensuring that you enable the profile for your new role. Also make sure you have at least 1 of the buttons ticked to show.
Drupal cache serves blank page
Using mod rewrite to stop attempted spam on the emailpage module
We inherited a site that was running a very old (probably un patched) version of Drupal 4.6. The site was getting a massive number of hits to the URL /emailpage - at least 20 a minute, even when there was no other traffic on the site.
This looked suspiciously like a mail header injection problem. Even though the server was not currently sending out any spam we figured that at some point in the past the emailpage module was running un secure, and the site got itself onto someone's spambot list :(.
Automatically subscribe new users to your simplenews newsletter
Creating a simple module to clear the Drupal 4.7 cache
The problem
Drupal offers some powerful caching features, but they are by no means perfect as we discovered when building the site http://www.booktribes.com.
Booktribes uses some simple custom blocks to display some semi-dynamic content, content such as the "rotating" lists of celebrity favourite books. Turning on Drupal page caching offers a significant performance boost to the site, but it means that our dynamic front page content suddenly becomes static - which is bad news.
So, the solution - write a simple module that will refresh the page cache a a given interval, every 15 minutes the cached pages are regenerated - its win win, the users see the content updating frequently and the server still feels the benefits of the page caching. Of course - it is worth remembering that Drupal will only cache pages for non-authenticated users.





