You are here

class SyndicateBlock in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/src/Plugin/Block/SyndicateBlock.php \Drupal\node\Plugin\Block\SyndicateBlock
  2. 9 core/modules/node/src/Plugin/Block/SyndicateBlock.php \Drupal\node\Plugin\Block\SyndicateBlock

Provides a 'Syndicate' block that links to the site's RSS feed.

Plugin annotation


@Block(
  id = "node_syndicate_block",
  admin_label = @Translation("Syndicate"),
  category = @Translation("System")
)

Hierarchy

Expanded class hierarchy of SyndicateBlock

File

core/modules/node/src/Plugin/Block/SyndicateBlock.php, line 22

Namespace

Drupal\node\Plugin\Block
View source
class SyndicateBlock extends BlockBase implements ContainerFactoryPluginInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a SyndicateBlock object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The config factory.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $configFactory) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->configFactory = $configFactory;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'block_count' => 10,
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function blockAccess(AccountInterface $account) {
    return AccessResult::allowedIfHasPermission($account, 'access content');
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    $title = $this->configuration['label'];
    return [
      '#theme' => 'feed_icon',
      '#url' => Url::fromUri('internal:/rss.xml'),
      '#title' => $title,
    ];
  }

}

Members