function TopBarItemLinkAttribute::build
Overrides TopBarItemBase::build
File
-
core/
modules/ navigation/ tests/ navigation_test_top_bar/ src/ Plugin/ TopBarItem/ TopBarItemLinkAttribute.php, line 29
Class
- TopBarItemLinkAttribute
- Provides a top bar item plugin for testing link attributes in the top bar.
Namespace
Drupal\navigation_test_top_bar\Plugin\TopBarItemCode
public function build() : array {
$links = [];
$featuredLinks['test_link'] = [
'page_action' => [
'#theme' => 'top_bar_page_action',
'#link' => [
'#type' => 'link',
'#title' => $this->t('Test link'),
'#url' => Url::fromRoute('entity.node.canonical', [
'node' => 1,
]),
'#attributes' => [
'title' => $this->t('Test link with attributes'),
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => json_encode([
'width' => 700,
]),
],
],
],
'icon' => [
'icon_id' => 'database',
],
];
return [
'#theme' => 'top_bar_page_actions',
'#page_actions' => $links,
'#featured_page_actions' => $featuredLinks,
'#attached' => [
'library' => [
'core/drupal.dialog.ajax',
],
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.