You are here

function content_load in Content Construction Kit (CCK) 5

Same name and namespace in other branches
  1. 6.3 content.module \content_load()
  2. 6 content.module \content_load()
  3. 6.2 content.module \content_load()

Load data for a node type's fields.

When loading one of the content.module nodes, we need to let each field handle its own loading. This can make for a number of queries in some cases, so we cache the loaded object structure and invalidate it during the update process.

1 call to content_load()
content_nodeapi in ./content.module
Implementation of hook_nodeapi().

File

./content.module, line 173
Allows administrators to associate custom fields to content types.

Code

function content_load(&$node) {
  $cid = 'content:' . $node->nid . ':' . $node->vid;
  if ($cached = cache_get($cid, 'cache_content')) {
    $extra = unserialize($cached->data);
    foreach ($extra as $key => $value) {
      $node->{$key} = $value;
    }
    return $extra;
  }
  else {
    $default_additions = _content_field_invoke_default('load', $node);
    if ($default_additions) {
      foreach ($default_additions as $key => $value) {
        $node->{$key} = $value;
      }
    }
    $additions = _content_field_invoke('load', $node);
    if ($additions) {
      foreach ($additions as $key => $value) {
        $default_additions[$key] = $value;
      }
    }
    cache_set($cid, 'cache_content', serialize($default_additions));
    return $default_additions;
  }
}