You are here

function cpn_node_load in Code per Node 7

Implements hook_node_load().

Adds "cpn" variable to the node object.

File

./cpn.module, line 353
Primary hook implementations.

Code

function cpn_node_load($nodes, $types) {
  $supported = FALSE;
  foreach ($types as $type) {
    if (variable_get('cpn_css_enabled_' . $type, FALSE) || variable_get('cpn_js_enabled_' . $type, FALSE)) {
      $supported = TRUE;
      break;
    }
  }
  if ($supported) {
    try {
      $result = db_query('SELECT nid, css, js, noscript FROM {cpn} WHERE nid IN (:nids)', array(
        ':nids' => array_keys($nodes),
      ));
      foreach ($result as $record) {
        $nodes[$record->nid]->cpn = array(
          'css' => $record->css,
          'js' => $record->js,
          'noscript' => $record->noscript,
        );
      }
    } catch (Exception $e) {
      watchdog('cpn', 'Error loading node records for CPN, were the database updates ran?');
    }
  }
}