Drupal Blog by joachim.noreiko
The Oxford Comma
Submitted by joachim.noreiko on Wed, 30/06/2010 - 16:59Here's a little function I wrote today because I needed to be able to turn a list of between one and three items into a string like 'apples, oranges, and pears', 'apples and pears', or just 'stairs'.
I figured I might as well handle everything in one place, and throw in the option to have an 'or' instead of an 'and'. There may be occasions you don't want the Oxford comma, but I can't think of any.
/**
Using Constants For Permission Names: WHY?
Submitted by joachim.noreiko on Wed, 30/06/2010 - 15:19I keep seeing this sort of thing in so many modules:
define("MY_MODULE_PERM_ACCESS_WIDGETS", 'access widgets');
// Names changed to protect the guilty ;)Am I missing something, or is this utterly pointless?
Once & Only Once: The Conversion To Drupal 7's FieldAPI
Submitted by joachim.noreiko on Tue, 06/04/2010 - 15:06I'm not a fan of repeating myself, or of doing the same work twice. So when I first got a look at FieldAPI back at DrupalCon Paris, my thought after 'Wow this is going to change everything,' was 'Every module that converts its custom data storage to this is going to be doing the same work, over and over'.
Help needed: using jQuery to show passwords as you type
Submitted by joachim.noreiko on Sun, 21/03/2010 - 21:57Today I found an article about password usability, which suggested that showing users what they type for their passwords is an improvement to usability.
You can try a working demo, which adds a 'show password' checkbox.
This had me wondering whether this is a feature we should consider having in Drupal.
Getting Stuff Done
Submitted by joachim.noreiko on Tue, 16/02/2010 - 18:07Basically, an initial patch went in, we opened followup issues for cleanup, the followup issues never got followed up, so what's in HEAD is a bit of a mess. — catch, in a recent issue comment
This happens far too often. I'm not linking to the specific issue in the Drupal 7 queue because I don't want to point fingers; this suffices to exemplify my point.
Services, or How I Learned We're All Just Secretly hook_menu()
Submitted by joachim.noreiko on Thu, 11/02/2010 - 00:02I am now batting nodes, complete with imagefield, between separate instances of Drupal with merriment and glee. For yes, I do have a working beta of Content distribution.
I'm about to quickly write a service to get CCK's content_fields() array from the remote, distributing site, so that the retrieving site can show a UI of possible values for a Views nodereference argument. Try it. It all makes sense once you do.
Why Is Writing Drupal Documentation Harder Than Writing Wikipedia?
Submitted by joachim.noreiko on Thu, 28/01/2010 - 21:51I used to write on Wikipedia, years ago when it was a wild frontier, we had barely 30 thousand articles, and not even my geek friends had heard of it from a source other than my blathering on about it.
Files Aren't Visible From All Domains Of A Site
Submitted by joachim.noreiko on Fri, 15/01/2010 - 15:37I had a fun afternoon a few months back when all the imagecache images broke on a site I'd just taken live. I've just figured it out, so I'm telling you about it.
This was the situation:
- subsite.client.com was where I was developing the site, one of a family of multisites.
- subsite.com was a parked domain that went to just this site. It was this I'd just pointed to the IP of the box and that wasn't showing any images.
On the development domain, all worked fine. On the subsite domain, nothing.
Multisite On localhost Without Virtual Hosts
Submitted by joachim.noreiko on Thu, 03/12/2009 - 15:15I've been putting off setting up multisite on my localhost for ages, mostly because in the past I've found getting Apache virtual hosts to work can be a bit tricky: not impossible, but the sort of thing where I could easily lose an hour on a minor thing I've forgotten to do. And after all, with a shiny new iMac and a hard drive whose proportions I can't even remember, why not just 'drush dl' all over again?
But I'm actually working on a multisite project at the moment, and suddenly getting this to work becomes more interesting than having another SVN copy of my code kicking around.
Given multisite can respond to subfolders, I was wondering if this could work when Drupal itself is in a subfolder, like this:
Counting Hooks
Submitted by joachim.noreiko on Tue, 17/11/2009 - 12:02This (fairly long) one-liner counts the number of implementations of each hook in your Drupal installation:
ack "Implements? hook_" | perl -e 'while (<>) { m[(hook_\w+)] and $hooks{$1}++; } foreach (keys %hooks) { print "$_ - $hooks{$_}\n"; }'To count only install file hooks, which was what I was doing, give ack the option "-G '.install'" thus:
ack "Implements? hook_" -G '.install' | perl -e 'while (<>) { m[(hook_\w+)] and $hooks{$1}++; } foreach (keys %hooks) { print "$_ - $hooks{$_}\n"; }'Six Reasons To Get A Handbook Page For Your Module
Submitted by joachim.noreiko on Fri, 06/11/2009 - 09:56Checkout view being currently disabled in ViewVC is a very good opportunity to remind everyone that linking to your README.txt file in CVS does not count as documentation on your project page!
Here are some things I, or anyone else, can do with a proper documentation page in what used to be called the handbooks section of drupal.org:
- Correct it.
- Expand on it.
- Clarify things for newbies.
Nodes As NIDs
Submitted by joachim.noreiko on Wed, 04/11/2009 - 16:41Is it just me who finds this poor style and potentially confusing:
<?php
function my_function($nodes) {
foreach ($nodes as $nid) {
// do stuff
}
}
?>To me, a variable names $nodes will be an array of nodes -- that is, node objects. If it's an array of nids, I would call it $nids to avoid confusion about what we have there.
I'm curious if other people agree (in other words, is it worth my time writing a patch for core or will it just lead to bikeshedding?)
Creating A Set Of Fields In One Swell Foop
Submitted by joachim.noreiko on Wed, 04/11/2009 - 16:19Situation: you need a heap of imagefields that more or less have the same setup. Let's not go into why.
You could spend half an hour bored witless clicking through the interface.
Or you could create just the one field, export the content type with content copy, and then doctor the code a little before importing it back in. Like this....
<?php
// The usual content type stuff here.
// Set of image fields
$image_fields = array(
'field_image_1' => 'Image 1',
'field_image_2' => 'Image 2',
// etc
);
foreach ($image_fields as $name => $label) {
Translation: Proving Complicated
Submitted by joachim.noreiko on Tue, 27/10/2009 - 12:50Editor's note: Joachim appreciates this may be a bit of a rant, and hopes people who read this and know more about the translation of Drupal than he will contribute via the Comments and tell him why he's being an idiot. But we decided to run with it because he makes some really valid points. I don't know if the translation interface was a part of the UI work for Drupal 7, but reading Joachim's experiences, I would hope so!
Rant starts here:
Small Core, Big Drupal, Tighter Contrib: Outer Core?
Submitted by joachim.noreiko on Sun, 18/10/2009 - 12:09I've been mulling this idea since Paris, trying to figure out the best way to present it.
But basically:
We want a smaller, slimmer, efficient core.
But we also want Drupal to, like, be useful.
We want contrib, at least the high-use end of contrib, to be smoother, more organized, released on time with core.
It's been suggested we have a contrib maintainer, who would have the unenviable task of managing a huge kaboodle.
Never Write A Line Of Code Again!
Submitted by joachim.noreiko on Tue, 18/08/2009 - 10:21Okay, so I lied. But module builder can save you a lot of time when writing custom modules.
And it now works with drush, too. I added support for drush a few weeks ago, which let you do things like "$ drush mb mymodule cron init menu nodeapi --write" and hey presto, a new module folder is created, with an info file and a module file, with hook implementations ready to do your (evil) bidding. (Note: this blog does not sanction use of Drupal, module builder, or drush for evil.)

