Why is my system CPU so high?

Had some performance issues with a client, recently. The server is an absolute beast, and should be able to easily handle the single website hosted on it. Alas, pages took forever to load (D7). A simple top showed that load was at about 60, and CPU utilization was at 10% for user and ... 95% for system. Wait what?

Read more »

Drupal filefield errors on node forms

in drupal, formAPI, filefield, error

For a recent client, I needed a node-add form in a custom path. Unfortunately, loading the form there via code (in order to prepopulate the node object) lead to all sorts of FileField errors, and the solution proved to be extraordinarily simple.

Read more »

No save button on vocabulary page?

I recently got a call from the content managers of a website I support, complaining that they couldn't reorder vocabulary terms any more. Specifically, the Save button was gone! Took me a while, but here is why, and how to solve it (if you just want the solution, scroll to the bottom)

Read more »

Making field collections play nice with hook_node_presave

Field Collections are basically multifields in Drupal 7. They're so much user-friendlier than having referenced nodes, and so much lighter. However, if you try to add items to them (that is, an unlimited field collection field) in hook_node_presave , you get stuck in an endless loop. If you have XDebug or similar, you will see the extremely unhelpful message " Maximum function nesting level of '100' reached, aborting!". So what now?

Read more »

Taxonomy term URLs gone FUBAR

One of the things I love about Drupal is the taxonomy system. It's convenient and stable... except when it's not. I got 404s for the term URLs (both system and alias) and the cryptic message "Notice: Undefined index: href in menu_local_tasks() (row 1973 in path2site/includes/menu.inc).". Well, here's what worked.

Read more »

(Finally) upgraded to Drupal 7

in drupal, upgrade

It's been long. Too long. I always wanted to upgrade my blog to D7... and never had the time or patience. Well, that's done!

Read more »

Drupal Tableselect with fields

in drupal, form api, fapi, fields, tableselect

We all know that Drupal provides the FormAPI, in which very powerful form elements exist (in our case, the tableselect element). This magical element behaves like a table, but has a checkbox for each line, and associated JS/CSS to handle checking rows. But it is normally impossible to add additional form elements on each row ( there have been many workarounds, but all seem hackish) due to the way Drupal handles form submission. This is how to have a clean (and simple!) way to go around those restrictions.

Read more »

Using views to show users who flagged nodes... by node.

in drupal, views, flags, templates, users

Flags is a very useful module that allows users to "flag" nodes that meet some criteria (eg type etc). Administratively, it might be of interest to show the users who have flagged a specific node. Unfortunately, that's both tricky and slightly non-intuitive.

Read more »

Dealing with checkboxes quickly

in drupal, fapi, forms, checkboxes

I've been working with the Forms API for some time. I've found a very useful shorthand for that today.

Read more »

Disabling a checkbox with FAPI without the javascript

in drupal, fapi, forms

Forms API is great, let me start there. However there are some cases where you want to ... ahem, go around it. One such cases is with checkboxes (where you have a number of checkboxes), specifically when you want to alter just one of the set. Here's how to fix that!

Read more »

FAPI form_alter missing fields

in drupal, cck, fapi, fields, form_alter

There are many occasions in which you would like to alter a form behavior, and it's normally very easy to do -- just implement hook_form_alter and you're done. There are cases though, where fields will be missing, and in those cases, you need a workaround.

Read more »

Drupal FAPI multistep errors on required fields

in drupal, error, fapi, multistep

One of the great usability features in the Drupal Form API are simple validators, such as #required. Just set it to true, and Drupal takes care of it. However, when in a multistep scenario, simple validators go haywire since moving to a different step validates the form. Normally, you cannot override form errors within your validation hook... but there's a workaround.

Read more »

Getting the value of a CCK field without node_load

in PHP, drupal, d6, cck, filefield, imagefield

More often than not, you'll come to a point where you need a field value of a node. Not the whole node, just a field. The most common case would appear to be when you need an image (say a promotional image). Some ways are easier than others for it, however you need to think of what you are doing under the hood.

Read more »

Nodequeue tricks - Per section block

in PHP, drupal, taxonomy, views, nodequeue

I assume that if you've build a relatively large site, you've stumbled on Nodequeue by now ( summary: it allows you to create lists of arbitrarily ordered nodes ). But clients always had a thing for imagining things that are normally tricky to do, and one of them is to create a block that has arbitrarily ordered content per section of the site, usually by taxonomy term.

Read more »

Access denied for admin pages show in admin theme

in drupal, 403, theming, bug

What every new developer in Drupal needs to get to his head (and hears all the time in the community), is that no matter what, you should never EVER hack core. Except when your problem is one that has absolutely no other solution. In our case, using an alternate administration theme, will cause access errors to administration pages to be rendered in that theme -- and that cannot be solved otherwise.

Read more »

Cloud Zoom Alternative

in drupal, Module, jquery

A client needed the ability to easily zoom into images in place. That is, display a small image, and when hovering, zoom a part of the image. In that spirit, I found the freely available cloud zoom library. Though I did find a Drupal module for that, it only exposed a very limited amount of options that are available, and the dev version, which included more features, had bugs (hence the dev). This is my implementation, which (hopefully) will help people out.

Read more »

Using different views for different vocabularies or terms

in drupal, taxonomy, views, tvi

You really aren't using Drupal right if you're not harnessing the power of taxonomy, and you haven't seen much of it until you understand views. The only limitation for me was that you have to streamline all terms to look alike, in order to fit in the same templating. Well, not anymore!

Read more »

Facebook share images

in facebook, drupal, share, meta

Every site today uses social buttons. It's become part of the basic functionality. And yet most have trouble dealing with and integral part of the whole sharing part -- choosing an image to accompayny the shared article.

Read more »

Styling rows in views

in drupal, views, css

If you're using Drupal without Views... you're probably doing it wrong (sic). Views really are almost a the only way to have full control over any content listing, with minimal effort.  You can even customize things on a per-field basis via template overrides. But how do you add particular classes to individual rows?

Read more »

Drupal forms and redirection

in drupal, form api

You've created a form through the forms API, and because you want some custom behavior, you need it to post back to you... so why does you get a 302 redirect when trying to process it?!

Read more »