You are here

function _nodeblock_prepare_nodeblock in Nodeblock 7

Helper function to prepare the nodeblock data before insert/update.

2 calls to _nodeblock_prepare_nodeblock()
nodeblock_node_insert in ./nodeblock.module
Implements hook_node_insert().
nodeblock_node_update in ./nodeblock.module
Implements hook_node_update().

File

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

Code

function _nodeblock_prepare_nodeblock($node) {
  $overrides = nodeblock_type_node_overrides($node->type);
  $values = _nodeblock_defaults($node->type);
  if (isset($node->nodeblock)) {

    // Set the real nid from the node. This is needed to make sure that they
    // match as they might be different when importing nodes e.g. via
    // node_export from another server where the nodeblock node has a
    // different nid. In this case, $node->nid already has been set to the
    // correct target nid by node_export.
    $node->nodeblock['nid'] = $node->nid;
    $values = $node->nodeblock + $values;
  }

  // Custom machine name is not selected, machine name
  // is not set user cannot override machine name.
  if (empty($values['custom_machine_name']) || !isset($values['machine_name']) || !isset($overrides['machine_name'])) {
    $values['machine_name'] = $node->nid;
  }

  // Node Block is used as block title field.
  if (nodeblock_type_node_override_block_title_field($node->type) == 'nodeblock') {

    // Custom block title is not selected or user cannot override block title.
    if (empty($values['custom_block_title']) || !isset($overrides['block_title'])) {
      $values['block_title'] = $node->title;
    }
  }
  return array_intersect_key($values, array_flip(array(
    'nid',
    'enabled',
    'machine_name',
    'block_title',
    'view_mode',
    'node_link',
    'comment_link',
    'translation_fallback',
  )));
}