function _nodereferrer_manage_cache in NodeReferrer 7
Helper function for Node API Hooks.
4 calls to _nodereferrer_manage_cache()
- nodereferrer_node_delete in ./
nodereferrer.module - Implementation of hook_node_delete().
- nodereferrer_node_insert in ./
nodereferrer.module - Implementation of hook_node_insert().
- nodereferrer_node_prepare in ./
nodereferrer.module - Implementation of hook_node_prepare().
- nodereferrer_node_update in ./
nodereferrer.module - Implementation of hook_node_update().
File
- ./
nodereferrer.module, line 862 - Defines a field type for backlinking referencing nodes.
Code
function _nodereferrer_manage_cache($node) {
// Clear content cache to help maintain proper display of nodes.
$nids = array();
$type = field_info_instances('node', $node->type);
if (!empty($type)) {
foreach ($type as $field => $instance) {
$fieldinfo = field_info_field($field);
if ($fieldinfo['type'] == 'node_reference') {
$node_field = isset($node->{$fieldinfo}['field_name']) ? $node->{$fieldinfo}['field_name'] : array();
if (isset($node_field['und'])) {
foreach ($node_field['und'] as $delta => $item) {
// Add referenced nodes to nids. This will clean up nodereferrer fields
// when the referencing node is updated.
$nids[$item['nid']] = $item['nid'];
}
}
}
}
}
// Clear Content cache for nodes that reference the node that is being updated.
// This will keep nodereference fields up to date when referred nodes are
// updated. @note this currenlty doesn't work all that well since nodereference
// doesn't respect publishing states or access control.
if (isset($node->nid)) {
$referrers = nodereferrer_referrers($node->nid);
$referrer_nids = array_keys($referrers);
$nids = array_merge($nids, $referrer_nids);
}
foreach ($nids as $nid) {
$printnode = node_load($nid);
$cid = "field:node:{$nid}";
// define a table to delete from or else this complains
cache_clear_all($cid, 'cache_field', TRUE);
}
}