TopBarItemLinkAttribute.php
Namespace
Drupal\navigation_test_top_bar\Plugin\TopBarItemFile
-
core/
modules/ navigation/ tests/ navigation_test_top_bar/ src/ Plugin/ TopBarItem/ TopBarItemLinkAttribute.php
View source
<?php
declare (strict_types=1);
namespace Drupal\navigation_test_top_bar\Plugin\TopBarItem;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\navigation\Attribute\TopBarItem;
use Drupal\navigation\TopBarItemBase;
use Drupal\navigation\TopBarRegion;
/**
* Provides a top bar item plugin for testing link attributes in the top bar.
*/
class TopBarItemLinkAttribute extends TopBarItemBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
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',
],
],
];
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
TopBarItemLinkAttribute | Provides a top bar item plugin for testing link attributes in the top bar. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.