class AggregatorFeedBlock

Same name in this branch

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

Plugin annotation


@Plugin(
  id = "aggregator_feed_block",
  admin_label = @Translation("Aggregator feed"),
  module = "aggregator",
  derivative = "Drupal\aggregator\Plugin\Derivative\AggregatorFeedBlock"
)

Hierarchy

Expanded class hierarchy of AggregatorFeedBlock

File

drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php, line 24
Contains \Drupal\aggregator\Plugin\Block\AggregatorFeedBlock.

Namespace

Drupal\aggregator\Plugin\Block
View source
class AggregatorFeedBlock extends BlockBase {

  /**
   * Overrides \Drupal\block\BlockBase::settings().
   */
  public function settings() {

    // By default, the block will contain 10 feed items.
    return array(
      'block_count' => 10,
    );
  }

  /**
   * Overrides \Drupal\block\BlockBase::access().
   */
  public function access() {

    // Only grant access to users with the 'access news feeds' permission.
    return user_access('access news feeds');
  }

  /**
   * Overrides \Drupal\block\BlockBase::blockForm().
   */
  public function blockForm($form, &$form_state) {
    $form['block_count'] = array(
      '#type' => 'select',
      '#title' => t('Number of news items in block'),
      '#default_value' => $this->configuration['block_count'],
      '#options' => drupal_map_assoc(range(2, 20)),
    );
    return $form;
  }

  /**
   * Overrides \Drupal\block\BlockBase::blockSubmit().
   */
  public function blockSubmit($form, &$form_state) {
    $this->configuration['block_count'] = $form_state['values']['block_count'];
  }

  /**
   * {@inheritdoc}
   */
  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,
        );
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AggregatorFeedBlock::access public function Overrides \Drupal\block\BlockBase::access(). Overrides BlockBase::access
AggregatorFeedBlock::blockForm public function Overrides \Drupal\block\BlockBase::blockForm(). Overrides BlockBase::blockForm
AggregatorFeedBlock::blockSubmit public function Overrides \Drupal\block\BlockBase::blockSubmit(). Overrides BlockBase::blockSubmit
AggregatorFeedBlock::build public function Builds and returns the renderable array for this block plugin. Overrides BlockPluginInterface::build
AggregatorFeedBlock::settings public function Overrides \Drupal\block\BlockBase::settings(). Overrides BlockBase::settings
BlockBase::blockValidate public function Adds block type-specific validation for the block form.
BlockBase::form public function Implements \Drupal\block\BlockPluginInterface::form(). Overrides BlockPluginInterface::form 1
BlockBase::getConfig public function Returns the configuration data for the block plugin.
BlockBase::setConfig public function Sets a particular value in the block settings.
BlockBase::submit public function Implements \Drupal\block\BlockPluginInterface::submit(). Overrides BlockPluginInterface::submit
BlockBase::validate public function Implements \Drupal\block\BlockPluginInterface::validate(). Overrides BlockPluginInterface::validate
BlockBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 1
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId