public function AggregatorFeedBlock::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/AggregatorFeedBlock.php, line 67
Contains \Drupal\aggregator\Plugin\Block\AggregatorFeedBlock.

Class

AggregatorFeedBlock
Provides an 'Aggregator feed' block with the latest items from the feed.

Namespace

Drupal\aggregator\Plugin\Block

Code

public function build() {

  // Plugin IDs look something like this: aggregator_feed_block:1.
  list(, $id) = explode(':', $this
    ->getPluginId());
  if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(
    ':fid' => $id,
  ))
    ->fetchObject()) {
    $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $this->configuration['block_count'], array(
      ':fid' => $id,
    ));
    $read_more = theme('more_link', array(
      'url' => 'aggregator/sources/' . $feed->fid,
      'title' => t("View this feed'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,
      );
    }
  }
}