SitemapSyndicateBlock.php in Site map 8
File
src/Plugin/Block/SitemapSyndicateBlock.php
View source
<?php
namespace Drupal\site_map\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 array(
'cache' => array(
'max_age' => 0,
),
);
}
protected function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'access content');
}
public function build() {
$config = \Drupal::config('site_map.settings');
$route_name = \Drupal::routeMatch()
->getRouteName();
if ($route_name == 'blog.user_rss') {
$feedurl = Url::fromRoute('blog.user_rss', array(
'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 = array(
'#theme' => 'feed_icon',
'#url' => $feedurl,
'#title' => t('Syndicate'),
);
$output = drupal_render($feed_icon);
$more_link = array(
'#type' => 'more_link',
'#url' => Url::fromRoute('site_map.page'),
'#attributes' => array(
'title' => t('View the site map to see more RSS feeds.'),
),
);
$output .= drupal_render($more_link);
return array(
'#type' => 'markup',
'#markup' => $output,
);
}
}