function webform_protected_downloads_node_load in Webform Protected Downloads 7
Implementation of hook_node_load().
File
- ./
webform_protected_downloads.module, line 331 - This file contains hook declarations and functions for the Webform Protected Downloads module.
Code
function webform_protected_downloads_node_load($nodes, $types) {
foreach ($nodes as $nid => $node) {
if (webform_protected_downloads_node_is_webform($node) && !isset($node->wpd['valid'])) {
// check if the node has protected files
if (webform_protected_downloads_node_has_protected_files($node->nid)) {
// check if the registered component still exists, needed, because we
// can't prevent webform from deleting a component that we might use
// as a mail field for the protected downloads
$result = db_query("SELECT COUNT(*) FROM {wpd_node_configuration} n LEFT JOIN {webform_component} c ON c.cid = n.mail_field_cid AND c.nid = n.nid WHERE n.nid = :nid AND c.cid IS NOT NULL", array(
':nid' => $node->nid,
))
->fetchAssoc();
$nodes[$nid]->wpd['valid'] = $result > 0;
}
else {
$nodes[$nid]->wpd['valid'] = TRUE;
}
// attach any private files to this node
$node->wpd['private_files'] = webform_protected_downloads_node_get_private_files($node);
// attach any protected files to this node
$node->wpd['protected_files'] = array();
foreach ($node->wpd['private_files'] as $file) {
if ($file->protected) {
$node->wpd['protected_files'][$file->fid] = $file;
}
}
// attach wpd configuration for this node
$node->wpd['config'] = webform_protected_downloads_get_configuration($node->nid);
$node->wpd['nid'] = $node->nid;
}
}
}