function node_admin_nodes

Returns the admin form object to node_admin_content().

See also

node_admin_nodes_submit()

node_admin_nodes_validate()

node_filter_form()

node_filter_form_submit()

node_multiple_delete_confirm()

node_multiple_delete_confirm_submit()

Related topics

1 call to node_admin_nodes()
node_admin_content in drupal/core/modules/node/node.admin.inc
Page callback: Form constructor for the content administration form.

File

drupal/core/modules/node/node.admin.inc, line 429
Content administration and module settings user interface.

Code

function node_admin_nodes() {
  $admin_access = user_access('administer nodes');

  // Build the 'Update options' form.
  $form['options'] = array(
    '#type' => 'details',
    '#title' => t('Update options'),
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
    '#access' => $admin_access,
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'node') . '/node.admin.css',
      ),
    ),
  );
  $options = array();
  foreach (module_invoke_all('node_operations') as $operation => $array) {
    $options[$operation] = $array['label'];
  }
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => 'approve',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#validate' => array(
      'node_admin_nodes_validate',
    ),
    '#submit' => array(
      'node_admin_nodes_submit',
    ),
  );

  // Enable language column and filter if multiple languages are enabled.
  $multilingual = language_multilingual();

  // Build the sortable table header.
  $header = array(
    'title' => array(
      'data' => t('Title'),
      'field' => 'n.title',
    ),
    'type' => array(
      'data' => t('Content type'),
      'field' => 'n.type',
      'class' => array(
        RESPONSIVE_PRIORITY_MEDIUM,
      ),
    ),
    'author' => array(
      'data' => t('Author'),
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    ),
    'status' => array(
      'data' => t('Status'),
      'field' => 'n.status',
    ),
    'changed' => array(
      'data' => t('Updated'),
      'field' => 'n.changed',
      'sort' => 'desc',
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    ),
  );
  if ($multilingual) {
    $header['language_name'] = array(
      'data' => t('Language'),
      'field' => 'n.langcode',
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    );
  }
  $header['operations'] = array(
    'data' => t('Operations'),
  );
  $query = db_select('node', 'n')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
  node_build_filter_query($query);
  if (!user_access('bypass node access')) {

    // If the user is able to view their own unpublished nodes, allow them
    // to see these in addition to published nodes. Check that they actually
    // have some unpublished nodes to view before adding the condition.
    if (user_access('view own unpublished content') && ($own_unpublished = db_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status', array(
      ':uid' => $GLOBALS['user']->uid,
      ':status' => 0,
    ))
      ->fetchCol())) {
      $query
        ->condition(db_or()
        ->condition('n.status', 1)
        ->condition('n.nid', $own_unpublished, 'IN'));
    }
    else {

      // If not, restrict the query to published nodes.
      $query
        ->condition('n.status', 1);
    }
  }
  $nids = $query
    ->fields('n', array(
    'nid',
  ))
    ->limit(50)
    ->orderByHeader($header)
    ->addTag('node_access')
    ->execute()
    ->fetchCol();
  $nodes = node_load_multiple($nids);

  // Prepare the list of nodes.
  $languages = language_list(LANGUAGE_ALL);
  $destination = drupal_get_destination();
  $options = array();
  foreach ($nodes as $node) {
    $l_options = $node->langcode != LANGUAGE_NOT_SPECIFIED && isset($languages[$node->langcode]) ? array(
      'language' => $languages[$node->langcode],
    ) : array();
    $options[$node->nid] = array(
      'title' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => $node
            ->label(),
          '#href' => 'node/' . $node->nid,
          '#options' => $l_options,
          '#suffix' => ' ' . theme('mark', array(
            'type' => node_mark($node->nid, $node->changed),
          )),
        ),
      ),
      'type' => check_plain(node_get_type_label($node)),
      'author' => theme('username', array(
        'account' => $node,
      )),
      'status' => $node->status ? t('published') : t('not published'),
      'changed' => format_date($node->changed, 'short'),
    );
    if ($multilingual) {
      $options[$node->nid]['language_name'] = language_name($node->langcode);
    }

    // Build a list of all the accessible operations for the current node.
    $operations = array();
    if (node_access('update', $node)) {
      $operations['edit'] = array(
        'title' => t('edit'),
        'href' => 'node/' . $node->nid . '/edit',
        'query' => $destination,
      );
    }
    if (node_access('delete', $node)) {
      $operations['delete'] = array(
        'title' => t('delete'),
        'href' => 'node/' . $node->nid . '/delete',
        'query' => $destination,
      );
    }
    if (module_invoke('translation_entity', 'enabled', 'node', $node
      ->bundle())) {
      $operations['translate'] = array(
        'title' => t('translate'),
        'href' => 'node/' . $node->nid . '/translations',
        'query' => $destination,
      );
    }
    $options[$node->nid]['operations'] = array();
    if (count($operations) > 1) {

      // Render an unordered list of operations links.
      $options[$node->nid]['operations'] = array(
        'data' => array(
          '#type' => 'operations',
          '#subtype' => 'node',
          '#links' => $operations,
        ),
      );
    }
    elseif (!empty($operations)) {

      // Render the first and only operation as a link.
      $link = reset($operations);
      $options[$node->nid]['operations'] = array(
        'data' => array(
          '#type' => 'link',
          '#title' => $link['title'],
          '#href' => $link['href'],
          '#options' => array(
            'query' => $link['query'],
          ),
        ),
      );
    }
  }

  // Only use a tableselect when the current user is able to perform any
  // operations.
  if ($admin_access) {
    $form['nodes'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $options,
      '#empty' => t('No content available.'),
    );
  }
  else {
    $form['nodes'] = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $options,
      '#empty' => t('No content available.'),
    );
  }
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  return $form;
}