public function SitemapSyndicateBlock::build in Site map 8
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ SitemapSyndicateBlock.php, line 43
Class
- SitemapSyndicateBlock
- Provides a 'Syndicate (site map)' block.
Namespace
Drupal\site_map\Plugin\BlockCode
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);
// Re-use drupal core's render element.
$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,
);
}