SitemapSyndicateBlock.php in Sitemap 2.0.x
File
src/Plugin/Block/SitemapSyndicateBlock.php
View source
<?php
namespace Drupal\sitemap\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
class SitemapSyndicateBlock extends BlockBase {
public function defaultConfiguration() {
return [
'cache' => [
'max_age' => 0,
],
];
}
protected function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'access content');
}
public function build() {
$config = \Drupal::config('sitemap.settings');
$route_name = \Drupal::routeMatch()
->getRouteName();
if ($route_name == 'blog.user_rss') {
$feedurl = Url::fromRoute('blog.user_rss', [
'user' => \Drupal::routeMatch()
->getParameter('user'),
]);
}
elseif ($route_name == 'blog.blog_rss') {
$feedurl = Url::fromRoute('blog.blog_rss');
}
else {
$feedurl = $config
->get('rss_front');
}
$feed_icon = [
'#theme' => 'feed_icon',
'#url' => $feedurl,
'#title' => t('Syndicate'),
];
$output = \Drupal::service('renderer')
->render($feed_icon);
$more_link = [
'#type' => 'more_link',
'#url' => Url::fromRoute('sitemap.page'),
'#attributes' => [
'title' => t('View the sitemap to see more RSS feeds.'),
],
];
$output .= \Drupal::service('renderer')
->render($more_link);
return [
'#type' => 'markup',
'#markup' => $output,
];
}
}