function comment_admin_overview

Form constructor for the comment overview administration form.

Parameters

$arg: The type of overview form ('approval' or 'new').

See also

comment_admin()

comment_admin_overview_validate()

comment_admin_overview_submit()

theme_comment_admin_overview()

Related topics

1 string reference to 'comment_admin_overview'
comment_admin in drupal/core/modules/comment/comment.admin.inc
Page callback: Presents an administrative comment listing.

File

drupal/core/modules/comment/comment.admin.inc, line 44
Admin page callbacks for the Comment module.

Code

function comment_admin_overview($form, &$form_state, $arg) {

  // Build an 'Update options' form.
  $form['options'] = array(
    '#type' => 'details',
    '#title' => t('Update options'),
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  if ($arg == 'approval') {
    $options['publish'] = t('Publish the selected comments');
  }
  else {
    $options['unpublish'] = t('Unpublish the selected comments');
  }
  $options['delete'] = t('Delete the selected comments');
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Action'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => 'publish',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );

  // Load the comments that need to be displayed.
  $status = $arg == 'approval' ? COMMENT_NOT_PUBLISHED : COMMENT_PUBLISHED;
  $header = array(
    'subject' => array(
      'data' => t('Subject'),
      'field' => 'subject',
    ),
    'author' => array(
      'data' => t('Author'),
      'field' => 'name',
      'class' => array(
        RESPONSIVE_PRIORITY_MEDIUM,
      ),
    ),
    'posted_in' => array(
      'data' => t('Posted in'),
      'field' => 'node_title',
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    ),
    'changed' => array(
      'data' => t('Updated'),
      'field' => 'c.changed',
      'sort' => 'desc',
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    ),
    'operations' => t('Operations'),
  );
  $query = db_select('comment', 'c')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
  $query
    ->join('node_field_data', 'n', 'n.nid = c.nid');
  $query
    ->addTag('node_access');
  $result = $query
    ->fields('c', array(
    'cid',
    'nid',
    'subject',
    'name',
    'changed',
  ))
    ->condition('c.status', $status)
    ->limit(50)
    ->orderByHeader($header)
    ->execute();
  $nids = array();
  $cids = array();

  // We collect a sorted list of node_titles during the query to attach to the
  // comments later.
  foreach ($result as $row) {
    $nids[] = $row->nid;
    $cids[] = $row->cid;
  }

  // Ensure all nodes are statically cached so that we do not have to load them
  // individually when getting their labels below.
  node_load_multiple($nids);
  $comments = comment_load_multiple($cids);

  // Build a table listing the appropriate comments.
  $options = array();
  $destination = drupal_get_destination();
  foreach ($comments as $comment) {

    // Remove the first node title from the node_titles array and attach to
    // the comment.
    $node_title = $comment->nid->entity
      ->label();
    $options[$comment
      ->id()] = array(
      'subject' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => $comment->subject->value,
          '#href' => 'comment/' . $comment
            ->id(),
          '#options' => array(
            'attributes' => array(
              'title' => truncate_utf8($comment->comment_body->value, 128),
            ),
            'fragment' => 'comment-' . $comment
              ->id(),
          ),
        ),
      ),
      'author' => theme('username', array(
        'account' => comment_prepare_author($comment),
      )),
      'posted_in' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => $node_title,
          '#href' => 'node/' . $comment->nid->target_id,
        ),
      ),
      'changed' => format_date($comment->changed->value, 'short'),
    );
    $links = array();
    $links['edit'] = array(
      'title' => t('edit'),
      'href' => 'comment/' . $comment
        ->id() . '/edit',
      'query' => $destination,
    );
    if (module_invoke('translation_entity', 'translate_access', $comment)) {
      $links['translate'] = array(
        'title' => t('translate'),
        'href' => 'comment/' . $comment
          ->id() . '/translations',
        'query' => $destination,
      );
    }
    $options[$comment
      ->id()]['operations']['data'] = array(
      '#type' => 'operations',
      '#links' => $links,
    );
  }
  $form['comments'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No comments available.'),
  );
  $form['pager'] = array(
    '#theme' => 'pager',
  );
  return $form;
}