I use Drupal 7.9 with Views module (if the latter is important). I've created a small module for my site that changes transliteration of Japanese words in articles from Latin to Cyrillics and vice versa (yes, I need such a thing). User sees a form with radio button set, chooses transliteration, his choice goes to $_COOKIE and then I change transliteration in article summary and body based on user's choice. Or better to say I'm trying to change it but it doesn't work. The code goes like this:

function mymodule_preprocess_node(&$variables) {
    /* Suppose we have a summary containing only one word 'Yamamoto' that has to be changed to 'Ямамото' */
    $variables['node']->body['und'][0]['summary'] = 'Ямамото';

After this code is executed, the changed variable has the correct value of 'Ямамото'. But in the main page for some reason I see the unchanged 'Yamamoto'. What am I doing wrong? Do I change the wrong field? Do I mess up working with parameters passed by reference? Do I use the wrong hook?


I believe that the node has already been rendered by the time template_preprocess_node() is called so changing any values on the node object will have no effect. You can try looking at $variables['node']->content to see if you can modify the text in that (I think this is the full HTML rendered node though, so lots of extra text/markup to deal with here).

You're probably better off using hook_node_load() instead. This gives you a chance to alter the node object directly before it gets rendered.

  • Oh. That's why it didn't work for me. Okay, thanks, I'll use $variables['content']. hook_node_load() for some reason is not called in my module, and when i write something plain and simple like function mymodule_node_load($nodes, $types) { die('Died on node_load'); } my site happily continues to work. I suspect it has something to do with the fact that I have a form in my module but am not very sure as I'm a newbie to Drupal. So I'll use $variables['content']. – Ari Linn Nov 19 '11 at 21:38
  • You can always open another question if you wanna try hook_node_load() in the future. Good luck! – rocketeerbkw Nov 19 '11 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.