function _nodesinblock_save in Nodes In Block 7
Same name and namespace in other branches
- 6 nodesinblock.module \_nodesinblock_save()
Function callback: save node settings into nodesinblock table and update block visibility pages.
3 calls to _nodesinblock_save()
- nodesinblock_node_delete in ./
nodesinblock.module - Implements hook_node_delete().
- nodesinblock_node_insert in ./
nodesinblock.module - Implements hook_node_insert().
- nodesinblock_node_update in ./
nodesinblock.module - Implements hook_node_update().
File
- ./
nodesinblock.module, line 350 - Nodes in block makes it possible to add multiple nodes in one block.
Code
function _nodesinblock_save($node, $op) {
// Delete old record.
db_delete('nodesinblock')
->condition('nid', $node->nid)
->execute();
// Save if node is not deleted
if ($op != 'delete' && $node->nodesinblock_delta != -1) {
$nodeinblock = new stdClass();
$nodeinblock->nid = $node->nid;
$nodeinblock->delta = $node->nodesinblock_delta;
$nodeinblock->weight = $node->nodesinblock_weight;
$nodeinblock->visibility = trim($node->nodesinblock_visibility);
$nodeinblock->render = $node->nodesinblock_render;
drupal_write_record('nodesinblock', $nodeinblock);
}
// Get visibility paths.
$visibility = array();
$result = db_query("SELECT visibility FROM {nodesinblock} nib INNER JOIN {node} n on n.nid = nib.nid WHERE nib.delta = :delta AND n.status = 1", array(
':delta' => $node->nodesinblock_delta,
));
foreach ($result as $row) {
$node_visibility = explode("\n", $row->visibility);
foreach ($node_visibility as $path) {
$visibility[] = trim($path);
}
}
// Update blocks table.
$visibility = array_unique($visibility);
db_update('block')
->condition('module', 'nodesinblock')
->condition('delta', $node->nodesinblock_delta)
->fields(array(
'visibility' => variable_get('nodesinblock_visibility_' . $node->nodesinblock_delta, '1'),
'pages' => implode("\n", $visibility),
))
->execute();
}