Evitant que el camp tí­tol sigui obligatori a drupal

Pot donar-se el cas que estiguis creant un tipus de contingut amb drupal, i que no vulguis que el camp tí­tol sigui obligatori.  I pot donar-se el cas també que a més, vulguis que et crei un camp autonuméric com a “tí­tol” o camp clau… el que vindria siguent un ID autonumèric en el sempre amic MSACCESS.

Per solventar-ho, com sempre dos mòduls que et fan part de la feina: serial field i auto node title… imprescindible tenir també el mòdul rules.

El procediment és ben fàcil: activar tots dos mòduls esmentats, afegir un camp serial al teu node i configurar en el tipus de contingut que el tí­tol sigui opcional o que sigui amagat i per tant que canvii el contingut per els patrons que ofereix token.  Fins aquí­ lo fàcil.  Veurem que podem guardar el node sense indicar un tí­tol, però al no tenir registrat encara el valor en la base de dades, l’objetiu no serà del tot el que esperavem ja eu apareixerà la definció literal del token i no el valor autonumèric.

Per resoldre això, haurem de crear una petita acció a token nostre que validi cada cop que gravem un node sense tí­tol per què faci ell automàticament un segon “guardar” agafant llavors els valors correctes des de la base de dades.

Hi ha una guia super aclaratòria a: http://drupal.org/node/615410

0. Obviously you have to have the Serial Field module installed. You will also need to add a field for your content type that is of the type serial. Furthermore, you will need to install the Rules module.

1. On the list of content types, click Edit next to the content type in question. In the section Automatic title generation, write the pattern for your title. To get the serial field value, look at the Replacement patterns help box for a section called CCK serial tokens for a token with the help text “Serial field value (unique per node type)”. Save the settings.

2. Go to admin/rules and create a rule with the following details:
– Event type: After saving new content
– Add Condition: Created content is SelectYourContentType
– Add Action: Execute custom PHP code (the PHP Filter module must be activated or else you won’t see this option) and enter the following code in the text area:
auto_nodetitle_operations_update(array($node->nid));
Basically, the node will run Automatic Nodetitles’ method auto_nodetitle_operations_update which updated the title of a certain node.

That should be it. Now, each time you create a new node of the type SelectYourContentType, the rule you just added will make sure that the Automatic Nodetitles module will update the title for the node so that your serial is actually added to the title.

NOTE. If you create a new node that has a serial field and get a warning that the table doesn’t exist (which won’t output the serial in the title, obviously), just re-install the Serial Field module. Make sure you first inactivate it, then the uninstall it and finally remove the serial directory on the server. Then install the module again.