1

I am programatically trying to create a custom node to store some content, which I would like to display on a page. Following is how I am executing it.

    $node = new StdClass();
    $node->name = $value;
    $node->title = $node->name;
    $node->language = LANGUAGE_NONE;
    $node->body[$node->language][0]['value']   = $javascript.$html;
    $node->body[$node->language][0]['summary'] = $type;
    $node->type = "custom_type";
    $node->created = time();
    node_save($node);

I notice that the content I inserted are present in the tables 'field_data_body' and 'field_revision_body' I try to load the node and get the content

   $query = new EntityFieldQuery();
   $entities = $query->entityCondition('entity_type', 'node')
              ->propertyCondition('type', 'custom_type')
              ->propertyCondition('title', $type)                         
              ->execute();
   if (!empty($entities['node'])) {
        $node = node_load(array_shift(array_keys($entities['node'])));
        $html = $html.$node->body[$node->language][0]['value'];
   }

But what puzzles me is how from where is the content being loaded. I deleted the entries in both 'field_data_body' and 'field_revision_body', but the content still gets loaded.

So how does drupal7 save and load the contents of the node body?

  • try to empty cache in admin/config/development/performance. don't forget fields taxonomy_index, noe, node_revision. – QQQ May 4 '13 at 5:50
  • 1
    Don't forget fields.. what is fields? taxonomy_index, node and node_revision are tables and neither have anything to do with the node bodies. – user49 May 4 '13 at 10:13
2

If you emptied out the field_data_body (and revision) table and you are still getting data that can only mean three things:

  1. you emptied the wrong table (wrong database or the right database with the wrong prefix)
  2. it's still cached (there's a clear cache button on the admin/config/development/performance page).
  3. You are not using SQL to store your fields. Do you have mongodb_field_storage enabled? Something even more exotic?

As for how it gets stored, node_save calls field_attach_insert (and node_load calls field_attach_load) which, in turn, calls the field storage module which I presume is field_sql_storage and so field_sql_storage_field_storage_write writes your database records and field_sql_storage_field_storage_load loads them.

Also note that array_shift(array_keys()) is wrong (E_STRICT error: Only variables should be passed by reference because array_shift takes a reference and array_keys is not returning by reference. Finally, you should feed your EntityFieldQuery code to the coder module to fix the coding standards: at least the code inside the if is indented wrong and the string concat operator (the dot) needs spaces on both sides. It hurts my eyes :)

  • I had to put sunglasses when I read the question. ;) – kiamlaluno May 4 '13 at 10:39
  • Awesome !!It was because if the data being cached by drupal ! Thanks !! – jayanth88 May 6 '13 at 13:10

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.