You are here

function nodeblock_node_insert in Nodeblock 7

Implements hook_node_insert().

1 call to nodeblock_node_insert()
nodeblock_node_update in ./nodeblock.module
Implements hook_node_update().

File

./nodeblock.module, line 645
Enables use of specified node types as custom blocks.

Code

function nodeblock_node_insert($node) {
  if (nodeblock_type_enabled($node->type)) {
    $values = _nodeblock_prepare_nodeblock($node);
    $values['nid'] = $node->nid;
    $values['translation_fallback'] = (int) $values['translation_fallback'];
    db_insert('nodeblock')
      ->fields($values)
      ->execute();

    // Rehash block list with this new block for all active themes.
    // @see _block_rehash().
    $themes = list_themes();
    foreach ($themes as $theme) {
      if ($theme->status) {
        $blocks = array(
          'nodeblock' => array(
            $node->nid => array(
              'info' => $node->title,
              'module' => 'nodeblock',
              'delta' => $node->nid,
              'theme' => $theme->name,
              'status' => 0,
              'region' => BLOCK_REGION_NONE,
              'pages' => '',
            ),
          ),
        );
        drupal_alter('block_info', $blocks, $theme, $blocks);
        if (isset($blocks['nodeblock'][$node->nid])) {
          drupal_write_record('block', $blocks['nodeblock'][$node->nid]);
        }
      }
    }
    $node->nodeblock = $values;
  }
}