function node_admin_nodes

Returns the admin form object to node_admin_content().

Related topics

1 string reference to 'node_admin_nodes'
node_menu in drupal/core/modules/node/node.module
Implements hook_menu().

File

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

Code

function node_admin_nodes() {

  // 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_field_data', 'n')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
  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 DISTINCT nid FROM {node_field_data} 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
    ->distinct()
    ->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::STATE_ALL);
  $destination = drupal_get_destination();
  $form['nodes'] = array(
    '#type' => 'table',
    '#header' => $header,
    '#empty' => t('No content available.'),
  );
  foreach ($nodes as $node) {
    $l_options = $node->langcode != Language::LANGCODE_NOT_SPECIFIED && isset($languages[$node->langcode]) ? array(
      'language' => $languages[$node->langcode],
    ) : array();
    $mark = array(
      '#theme' => 'mark',
      '#mark_type' => node_mark($node->nid, $node->changed),
    );
    $form['nodes'][$node->nid]['title'] = array(
      '#type' => 'link',
      '#title' => $node
        ->label(),
      '#href' => 'node/' . $node->nid,
      '#options' => $l_options,
      '#suffix' => ' ' . drupal_render($mark),
    );
    $form['nodes'][$node->nid]['type'] = array(
      '#markup' => check_plain(node_get_type_label($node)),
    );
    $form['nodes'][$node->nid]['author'] = array(
      '#theme' => 'username',
      '#account' => $node,
    );
    $form['nodes'][$node->nid]['status'] = array(
      '#markup' => $node->status ? t('published') : t('not published'),
    );
    $form['nodes'][$node->nid]['changed'] = array(
      '#markup' => format_date($node->changed, 'short'),
    );
    if ($multilingual) {
      $form['nodes'][$node->nid]['language_name'] = array(
        '#markup' => 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 ($node
      ->isTranslatable()) {
      $operations['translate'] = array(
        'title' => t('Translate'),
        'href' => 'node/' . $node->nid . '/translations',
        'query' => $destination,
      );
    }
    $form['nodes'][$node->nid]['operations'] = array();
    if (count($operations) > 1) {

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

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