1 node.module node_page_default()

Menu callback; Generate a listing of promoted nodes.

Return value

array: An array in the format expected by backdrop_render().

See also

node_menu()

File

core/modules/node/node.module, line 2333
The core module that allows content to be submitted to the site.

Code

function node_page_default() {
  // Check for custom <front> page
  $front = config_get('system.core', 'site_frontpage');
  if ($front != 'node') {
    backdrop_goto('<front>', array(), '301');
  }
  else {
    $site_config = config('system.core');
    $select = db_select('node', 'n')
      ->fields('n', array('nid', 'sticky', 'created'))
      ->condition('n.promote', 1)
      ->condition('n.status', 1)
      ->orderBy('n.sticky', 'DESC')
      ->orderBy('n.created', 'DESC')
      ->extend('PagerDefault')
      ->limit($site_config->get('default_nodes_main'))
      ->addTag('node_access');

    $nids = $select->execute()->fetchCol();

    if (!empty($nids)) {
      $nodes = node_load_multiple($nids);
      $build = node_view_multiple($nodes);

      // 'rss.xml' is a path, not a file, registered in node_menu().
      backdrop_add_feed('rss.xml', $site_config->getTranslated('site_name') . ' ' . t('RSS'));
      $build['pager'] = array(
        '#theme' => 'pager',
        '#weight' => 5,
      );
      backdrop_set_title('');
    }
    else {
      backdrop_set_title(t('Welcome to @site-name', array('@site-name' => $site_config->getTranslated('site_name'))), PASS_THROUGH);

      $default_message = '<p>' . t('No content has been promoted yet.') . '</p>';
      $default_links = array();
      if (_node_add_access()) {
        $default_links[] = l(t('Add content'), 'node/add');
      }
      if (!empty($default_links)) {
        $default_message .= theme('item_list', array('items' => $default_links));
      }

      $build['default_message'] = array(
        '#markup' => $default_message,
        '#prefix' => '<div id="first-time">',
        '#suffix' => '</div>',
      );
    }
    return $build;
  }
}