drupal-planet

Drupal is a mighty fine Content Management System which we at Leafish use regularly. This section contains ideas, code snippets and modules which I thought may come in useful for Drupal admins and developers. I won't be officially supporting this code, but feel free to contact me if you have any problems or suggestions.

See also the list of my official projects on drupal.org (requires you to be logged in to drupal.org).

More testing with Codeception and Drupal projects

20th May
2013

This is a bit of a follow-up to Mike Bell's introductory article on using Codeception to create Drupal test suites. He concludes by stating he "need[s] to figure out a way of creating a Codeception module which allows you to plug in a Drupal testing user (ideally multiple so you can test each role) and then all the you have to do is call a function which executes the above steps to confirm your logged in before testing authenticated behaviour."

"Something along the lines of:

$I->drupalLogin('editor');

So, after skimming through Codeception and Mink documentation, I've tinkered with two potential ways of achieving this... for acceptance testing at least.

A crude toolbox

The first method is to use two custom classes to provide details of (a) a general Drupal site and (b) the specific site to be tested. This idea stemmed from this article which suggests that including literals - such as account credentials, paths and even form labels - in tests is bad practice. What if the login button label changes?

Drupal 6 Attachment Views

13th Apr
2010

drupal6_attachment_views_book.jpgThe kind folks at Packt Publishing have decided to send me a copy of the newly published Drupal 6 Attachment Views. This book aims to "teach Drupal developers across the experience spectrum how to use Attachment displays in Views, to make quick progress in functionality and [give] added value to users."

Publisher's overview:

  • Quickly learn about painlessly increasing the functionality of your Drupal 6 web site
  • Get more from your Views than you thought possible
  • Topics provide rapid instruction and results
  • Concise, targeted information rather than voluminous reference material
  • An informal, interactive style

Views has become the most-installed contributed module for Drupal - its also one of the first installed for most of our projects at Leafish. I'm looking forward to reading it and I'll be writing my thoughts here at some point soon.

Quick and dirty jQZoom with Drupal e-commerce and imagecache

2nd Apr
2010

jqzoom_drupal.pngRecently I integrated the nifty jQZoom jQuery plug-in into a client's site built on Drupal 5 and Drupal e-commerce 5.x-3.6. A jQZoom module for Drupal does exist, but here I'm going to outline the few simple steps required to get the script working with images output via a node template (or the Contemplate module).

For starters, on the site we have the following Imagecache presets:

  • product_full: "full-size" version, actually scaled to an width of 600px;
  • product_main: the "main image", used for display on a product node;
  • product_thumb: a thumbnail, used in product node teasers and for switching between product images.

The product nodes are templated to output several product images, something like this:

Role Weights gets Token support and a 6.x branch

22nd Jun
2009

Role Weights finally gets a bit of loving in the form of a 5.x-1.4 release with a couple of new features, namely Token support for a user's lightest and heaviest roles and the optional re-ordering of /admin/user/roles and /admin/user/access forms by role weight. These features were introduced in 5.x-1.3, however 5.x-1.4 also fixes a bug which left orphaned entries in the role_weights table after roles got deleted.

I've also branched for 6.x compatibility (at last) - snapshots from 6.x-1.x-dev should be functional and in line feature-wise with 5.x-1.4, bar Views 2 support. I'd love to improve Role Weights for 6.x: re-writing support for Views 2 and adding drag and drop re-ordering of roles being two areas that need some attention, but I'm just too darn short on time at the moment. As always, patches and reviews are welcome in the issue queue!

As a side note, I found this reference pretty useful regarding some function/API changes not mentioned elsewhere.

Simple permissions for uploads per node type

19th Aug
2008

Simple bit of Drupal module code from yesterday: permissions are provided for each node type which can have attachments, providing a more granular permission set based on node type. Then, we alter any node add/edit forms and set the #access property for the attachments part of the form based on these new permissions.

Check the code out after the break, hope its of some use somewhere. Does anyone have any thoughts on unsetting form elements like this? Is it a wise thing to do, or is there a better way? Cheers to those who commented, I've modified the snippet accordingly.

Listing authenticated users without roles

1st Jul
2008

Sometimes we'd like to list users who have registered with a Drupal site, but haven't been placed into any proper roles yet via subscriptions, purchases, membership approval or whatever.

Try this join query to get started:

  1. SELECT users.uid, name, created, access, login, status
  2. FROM {users}
  3. LEFT OUTER JOIN {users_roles}
  4. ON users.uid = users_roles.uid
  5. WHERE users_roles.uid IS NULL AND users.uid != 0