You are here

function bg_image_node_options in Background Images 6

Same name and namespace in other branches
  1. 7 bg_image.module \bg_image_node_options()

Returns an array of nids to node titles for the configured node type. Useful for select lists.

Parameters

$include_nid: Include the nid as text after the title. TRUE or FALSE. e.g.: array(1 => 'node title [nid: 1]')

1 call to bg_image_node_options()
bg_image_context_reaction_bg_image::options_form in plugins/bg_image_context_reaction_bg_image.inc
Allow admins to provide a section title, section subtitle and section class.

File

./bg_image.module, line 552
Allows for customizable background images per page

Code

function bg_image_node_options($include_nid = TRUE, $include_random = TRUE) {
  $node_type = variable_get('bg_image_node_type', '');

  // Our query
  $sql = "SELECT nid, title FROM {node} WHERE type = '%s'";
  $query = db_query($sql, array(
    $node_type,
  ));
  $node_options = array();
  while ($record = db_fetch_object($query)) {
    if ($include_nid) {
      $node_options[$record->nid] = $record->title . ' [nid:' . $record->nid . ']';
    }
    else {
      $node_options[$record->nid] = $record->title;
    }
  }
  if (!$node_options) {
    $node_type_path = str_replace('_', '-', $node_type);
    drupal_set_message("You don't have any {$node_type} nodes created yet. You must <a href=\"/node/add/{$node_type_path}\">create at least one {$node_type} node</a> before you can assign background images to pages.", 'warning');
    return FALSE;
  }
  else {
    if ($include_random) {
      return array(
        0 => '- Random -',
      ) + $node_options;
    }
    else {
      return $node_options;
    }
  }
}