public function PrintableLinksBlock::build in Printer and PDF versions for Drupal 8+ 2.x
Same name and namespace in other branches
- 8 src/Plugin/Block/PrintableLinksBlock.php \Drupal\printable\Plugin\Block\PrintableLinksBlock::build()
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/ PrintableLinksBlock.php, line 158
Class
- PrintableLinksBlock
- Provides a printable links block for each printable entity.
Namespace
Drupal\printable\Plugin\BlockCode
public function build() {
$entity_type = $this
->getDerivativeId();
$route_match = $this->routematch
->getMasterRouteMatch();
$route_entity = $route_match
->getParameter($entity_type);
$entity_id = $route_entity ? $route_entity
->id() : 'NULL';
$build = [
'#cache' => [
'contexts' => [
'route',
],
'tags' => [
$entity_type . ':' . $entity_id,
],
'max-age' => $this->configuration['max_age'] ?: 0,
],
];
if ($route_entity) {
return $build + [
'#theme' => 'links__entity__printable',
'#links' => $this->linkBuilder
->buildLinks($this->routematch
->getMasterRouteMatch()
->getParameter($entity_type)),
];
}
else {
return $build;
}
}