The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

Closures in PHP 5.3 and PHP 5.4

Submitted by nk on Thu, 2011-05-19 03:18

The up and coming PHP 5.4 NEWS contains a cryptic entry "Added closure $this support back". This inspired me to write a blog post on closures because we might to want use them in Drupal 8*. Here is the simplest closure example

The mistake we made in templating

Submitted by nk on Sun, 2011-05-15 09:26

In a long and fierce debate with Jen Lampton (mikey_p, HedgeMage and heyrocker was involved some as well) we have arrived to an incredibly important realization: theming newbies apparently don't find simple logic (if, print, function calls) problematic they have problems with data structures!

About entity / field interaction -- remote entities

Submitted by nk on Fri, 2011-05-06 08:19

Most entities you meet in Drupal 7 are pretty complex objects stored in a local database. That's not something the field system expects. The field system, in fact, will never use more than entity_extract_ids to interface with your entities by design. Both that function and the field system will use metadata from hook_entity_info so that can't be skipped. This is how you can interact with the fields system if you just pull some entity data out of thin air (like a web service):

$skeleton_entity = entity_create_stub_entity($entity_type, array($entity_id, $revision_id, $bundle));
field_attach_load($entity_type, array($entity_id => $skeleton_entity));

The $revision_id and the $bundle are optional. Every other attach function has a similar signature. Happy skeleton coding!

The new Relation module

Submitted by nk on Mon, 2011-05-02 17:02

I plan to create a screencast as well but meanwhile, here is a useful guide to the new Relation 1.0 alpha 2. We have relation entities which describe the relation between two or more endpoint entities. Endpoints entities are described by an entity_id, entity_type pair which is stored in a special field called endpoints. This a relation_endpoint type field, you can't create more of this type in the UI nor you can delete the single field of this type from the UI.

AJAX default page

Submitted by nk on Fri, 2011-04-08 21:45

By default AJAX submits to system/ajax and retrieves the form from cache. So if your form depends something from the page it originally appeared on it then you need to store that in $form_state, the whole of $form_state is cached alongside of the form (only a few internal keys are not).

I fought AJAX and I won

Submitted by nk on Fri, 2011-04-08 10:58

What I wanted, stupid me, change a select box, get my node form to rebuild on an "AJAX submit" and display some changed elements. Well, AJAX does not fire form level submit handlers (this is supposedly a good thing). But, the form only rebuilds if the "rebuild" flag gets set ($form_state['rebuild']) by a submit handler and a submit handler only -- which are not fired. Opsie! While a custom form surely can do something in #process, #after_build etc a node form really wants to be rebuilt. Seems like a stalemate.

Anyone needs a laptop?

Submitted by nk on Tue, 2011-03-29 09:08

The Drupal community helped me to get a Panasonic CF-Y5. I no longer need it so I am planning on passing it on. The tech might be a bit dated but still, it's a capable, very lightweight (1.5kg) machine with 2.5GB of RAM, a dual core first generation Intel Core Duo L2400 CPU and a 60GB HDD. The 14" screen is 1400 x 1050. I have two batteries for it, one original, one OEM. Both last couple hours, I only used the machine recently on planes so I only know the without wifi capability: the original does about 4 hrs. The bottom of the laptops is full of scratches the rest is quite good (well, it's a business rugged Panasonic so it's hardly a surprise). Drop me a line if you are a Drupal contributor and need a laptop.


Submitted by nk on Thu, 2011-03-17 23:47

Seems the community is overly happy with the git migration and it's right to be. But I would like to quietly remind everyone one part of our success is us being centralized. One part the git migration is beneficial to this because all those projects that went off to github can return home. On another part all these "sandboxes" have a danger of everyone going off into their own little corner. Oh yes, our long time core contributors will still post patches and just play nice but ... maybe not.

Make git work more similar to cvs

Submitted by nk on Sun, 2011-02-27 06:35

If you used bzr/cvs/svn checkouts and want something similar then in the repository root do:

git clone git://
cd myproject
git config branch.autosetuprebase always
git config push.default current
git config branch.$(git symbolic-ref HEAD | cut -c 12-).rebase true
echo 'git push' > .git/hooks/post-commit
chmod 755 .git/hooks/post-commit

After this (on at least on Linux and Mac OS X)

  1. Contents will be pushed after every commit
  2. new branches will rebase after every pull.
  3. The only existing branch (master but can be something else with for example git clone --branch 6.x-1.x use the instruction on the Git instructions page of your project for this step) will rebase after every pull.

It does not abort commits if the local repo is behind remote, however. I would love to see tips on how to do that.

The "wonder" git documentation

Submitted by nk on Fri, 2011-02-25 08:49

lut4rp gave me a link today. I understood git. In minutes. Miracles!

you can only really use Git if you understand how Git works. Merely memorizing which commands you should run at what times will work in the short run, but it’s only a matter of time before you get stuck or, worse, break something.

Half of the existing resources on Git, unfortunately, take just that approach: they walk you through which commands to run when, and expect that you should do fine if you just mimic those commands. The other half does go through all the concepts, but from what I have seen, they explain Git in a manner that assumes you already understand how Git works.

The docs is at