1 block.overview_content.inc DashboardOverviewContentBlock::getContent()

Return the content of a block.

Return value

mixed:

Overrides Block::getContent

File

core/modules/dashboard/includes/block.overview_content.inc, line 64
Dashboard block displaying information about content, including:

Class

DashboardOverviewContentBlock
@file Dashboard block displaying information about content, including:

Code

function getContent() {
  $settings = $this->settings;

  // Not cached since comment and node CRUD operations are likely to be more
  // frequent than Dashboard access events.
  $items = array();
  $types = node_type_get_types();
  $comment_enabled = module_exists('comment') && $settings['comment_enabled'];

  foreach ($types as $machine => $node_type) {
    // Compare against node type option on block settings.
    if (in_array($machine, $settings['types']) || empty($settings['types'])) {
      $type_count = db_query("SELECT count(*) FROM {node} WHERE type = :type and status = 1", array(':type' => $machine))->fetchField();
      $content_data[$machine] = format_plural($type_count, '1 @type item', '@count @type items', array('@type' => t($node_type->name)));

      // Check if Comment module is enabled.
      if ($comment_enabled) {
        // Compare against comment options on block settings.
        if (in_array($machine, $settings['comment_types'])) {
          $comment_count = db_query("SELECT count(DISTINCT cid) FROM {comment} c INNER JOIN {node} n ON c.nid = n.nid WHERE n.type = :type and c.status = 1 AND n.status = 1", array(':type' => $machine))->fetchField();

          // Compare against unapproved option checkbox on block settings.
          if ($settings['comment_include_unapproved']) {
            $unapproved_count = db_query("SELECT count(DISTINCT c.cid) FROM {comment} c INNER JOIN {node} n ON c.nid = n.nid WHERE n.type = :type and c.status = 0 AND n.status = 1", array(':type' => $machine))->fetchField();
            $content_data[$machine . '_comments_unapproved'] = format_plural($unapproved_count, '1 unapproved', '@count unapproved');
            $comment_count += $unapproved_count;
          }

          $content_data[$machine . '_comments'] = format_plural($comment_count, '1 comment', '@count comments');
        }
      }
      $line = $content_data[$machine];
      $line .= (isset($content_data[$machine . '_comments'])) ? ' with ' . $content_data[$machine . '_comments'] : '';
      $line .= (isset($content_data[$machine . '_comments_unapproved'])) ? ' (' . $content_data[$machine . '_comments_unapproved'] . ')' : '';
      $items[] = $line;
    }
  }

  $panel = array(
    '#theme' => 'dashboard_panel__overview_content',
  );
  $panel['list'] = array(
    '#theme' => 'item_list',
    '#items' => $items,
  );
  if (user_access('administer nodes') || user_access('access content overview')) {
    $panel['link'] = array(
      '#theme' => 'link',
      '#path' => 'admin/content',
      '#text' => t('Manage content'),
    );
  }

  return $panel;
}