public function AggregatorCategoryBlock::build

Builds and returns the renderable array for this block plugin.

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockRenderController

File

drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php, line 67
Contains \Drupal\aggregator\Plugin\Block\AggregatorCategoryBlock.

Class

AggregatorCategoryBlock
Provides an 'Aggregator category' block for the latest items in a category.

Namespace

Drupal\aggregator\Plugin\Block

Code

public function build() {
  $id = $this
    ->getPluginId();
  if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(
    ':cid' => $id,
  ))
    ->fetchObject()) {
    $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(
      ':cid' => $category->cid,
    ));
    $read_more = theme('more_link', array(
      'url' => 'aggregator/categories/' . $category->cid,
      'title' => t("View this category's recent news."),
    ));
    $items = array();
    foreach ($result as $item) {
      $items[] = theme('aggregator_block_item', array(
        'item' => $item,
      ));
    }

    // Only display the block if there are items to show.
    if (count($items) > 0) {
      return array(
        '#children' => theme('item_list', array(
          'items' => $items,
        )) . $read_more,
      );
    }
    return array();
  }
}