You are here

function nodeblock_node_presave in Nodeblock 7

Implements hook_node_presave().

File

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

Code

function nodeblock_node_presave($node) {
  if (nodeblock_type_enabled($node->type) && isset($node->nodeblock)) {
    $block_title_field = nodeblock_type_node_override_block_title_field($node->type);
    $overrides = nodeblock_type_node_overrides($node->type);
    $values = $node->nodeblock;

    // Node Block is NOT used as block title field.
    if ($block_title_field != 'nodeblock') {
      foreach (_nodeblock_node_languages($node) as $langcode) {

        // Custom block title is not selected or user cannot
        // override block title.
        if (empty($values['custom_block_title']) || !isset($overrides['block_title'])) {

          // Fill block title field with the node title.
          $node->{$block_title_field}[$langcode][0]['value'] = _nodeblock_node_title($node, $langcode);
        }
      }
    }
  }
}