Persistent Random Node Titles for Drupal Nodes

Ever wanted to have random but persistent node titles for your Drupal nodes? I was in need for it for a reservation system. Of course once a node has got its random title, it should keep it forever.

You cann assign persistent random node titles to any content type. If not already installed download and enable the following modules

  • cck
  • cck textfields
  • auto_nodetitle

First I though auto_nodetitle is enough. But it turned out, that auto_nodetitle recalculates the node title everytime the node is saved. This means just a simple php snippet generating some random string isn't enough, because this way your node title changes everytime it gets saved. That's not what we want

Ok, here's the cook book:

  1. Go the fields administartino page of your content type, in my case this is admin/content/node-type/zuweisung/fields.
  2. Add a new field called "hidden_title" of type Text.
  3. Go to the administration page of your content type, in my case this is admin/content/node-type/zuweisung.
  4. Set "Automatically generate the title and hide the title field".
  5. In the "Pattern for the title:"add the following code snippet

    <?php
      if (!$node->field_hidden_title[0]['value']) {
        $node->field_hidden_title[0]['value'] = substr(sha1(microtime()),0,10);
      }
      return $node->field_hidden_title[0]['value'];
    ?>
  6. Check "Evaluate PHP in pattern."

Thats it. The next time you create or save a node of this content type it'll get a pseudo random node title which never changes.