public function BackLinkBlock::build in Opigno Learning path 3.x
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 SystemBreadcrumbBlock::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ BackLinkBlock.php, line 82
Class
- BackLinkBlock
- Provides a backlinkblock block.
Namespace
Drupal\opigno_learning_path\Plugin\BlockCode
public function build() {
$config = $this->configuration;
/** @var \Drupal\Core\Link[] $links */
$links = $this
->getLinks();
/** @var \Drupal\Core\Link $last_link */
$last_link = array_pop($links);
if ($last_link instanceof Link) {
return [
'#type' => 'inline_template',
'#template' => '<div class="back-btn d-none d-lg-block {{js_button}}"><a href="{{context}}"><i class="fi fi-rr-angle-small-left d-lg-none"></i><i class="fi fi-rr-arrow-left d-none d-lg-block"></i>{{context_title}}</a></div>',
'#context' => [
'context_title' => $this
->t('Back'),
'context' => $last_link
->getUrl()
->toString(),
],
'#attached' => [
'library' => [
'opigno_learning_path/back_button',
],
'drupalSettings' => [
'learning_path_back_link' => [
'js_button' => $this
->isOverrideJS(),
],
],
],
];
}
return [];
}