class RecentContentBlock

Provides a 'Recent content' block.

Plugin annotation


@Plugin(
  id = "node_recent_block",
  admin_label = @Translation("Recent content"),
  module = "node"
)

Hierarchy

Expanded class hierarchy of RecentContentBlock

File

drupal/core/modules/node/lib/Drupal/node/Plugin/Block/RecentContentBlock.php, line 23
Contains \Drupal\node\Plugin\Block\RecentContentBlock.

Namespace

Drupal\node\Plugin\Block
View source
class RecentContentBlock extends BlockBase {

  /**
   * Overrides \Drupal\block\BlockBase::settings().
   */
  public function settings() {
    return array(
      'block_count' => 10,
    );
  }

  /**
   * Overrides \Drupal\block\BlockBase::access().
   */
  public function access() {
    return user_access('access content');
  }

  /**
   * Overrides \Drupal\block\BlockBase::blockForm().
   */
  public function blockForm($form, &$form_state) {
    $form['block_count'] = array(
      '#type' => 'select',
      '#title' => t('Number of recent content items to display'),
      '#default_value' => $this->configuration['block_count'],
      '#options' => drupal_map_assoc(array(
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19,
        20,
        25,
        30,
      )),
    );
    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() {
    if ($nodes = node_get_recent($this->configuration['block_count'])) {
      return array(
        '#theme' => 'node_recent_block',
        '#nodes' => $nodes,
      );
    }
    else {
      return array(
        '#children' => t('No content available.'),
      );
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
RecentContentBlock::access public function Overrides \Drupal\block\BlockBase::access(). Overrides BlockBase::access
RecentContentBlock::blockForm public function Overrides \Drupal\block\BlockBase::blockForm(). Overrides BlockBase::blockForm
RecentContentBlock::blockSubmit public function Overrides \Drupal\block\BlockBase::blockSubmit(). Overrides BlockBase::blockSubmit
RecentContentBlock::build public function Builds and returns the renderable array for this block plugin. Overrides BlockPluginInterface::build
RecentContentBlock::settings public function Overrides \Drupal\block\BlockBase::settings(). Overrides BlockBase::settings