Loading core/modules/navigation/templates/top-bar-page-actions.html.twig +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ {% include 'navigation:toolbar-button' with { text: link['#title'], html_tag: 'a', attributes: create_attribute().setAttribute('href', link['#url']|render|default(null)), attributes: create_attribute(link['#attributes']|default([])).setAttribute('href', link['#url']|render|default(null)), modifiers: ['primary'], icon: featured_page_action.icon, } only %} Loading core/modules/navigation/tests/navigation_test_top_bar/navigation_test_top_bar.info.yml 0 → 100644 +7 −0 Original line number Diff line number Diff line name: Navigation test top bar description: 'Provides test functionality for top bar in navigation module' package: Testing version: VERSION type: module dependencies: - drupal:navigation core/modules/navigation/tests/navigation_test_top_bar/src/Plugin/TopBarItem/TopBarItemLinkAttribute.php 0 → 100644 +63 −0 Original line number Diff line number Diff line <?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. */ #[TopBarItem( id: 'test_item_link_attribute', region: TopBarRegion::Actions, label: new TranslatableMarkup('Test Item Link Attribute'), )] 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', ], ], ]; } } core/modules/navigation/tests/src/Functional/NavigationTopBarTest.php +5 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ class NavigationTopBarTest extends PageCacheTagsTestBase { */ protected static $modules = [ 'navigation', 'navigation_test_top_bar', 'node', 'layout_builder', 'test_page_test', Loading Loading @@ -92,6 +93,10 @@ public function testTopBarVisibility(): void { $this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/a[contains(@class, 'toolbar-button--icon--pencil')]", "Edit"); $this->assertSession()->elementAttributeContains('xpath', "(//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/button)[1]", 'class', 'toolbar-button--icon--dots'); // Verify that the action link contains an extra attribute. $this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/a[contains(@class, 'toolbar-button--icon--database')]", "Test link"); $this->assertSession()->elementAttributeContains('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/a[contains(@class, 'toolbar-button--icon--database')]", 'data-dialog-type', 'modal'); // Find all the dropdown links and check if the top bar is there as well. $toolbar_links = $this->mink->getSession()->getPage()->find('xpath', '//*[@id="top-bar-page-actions"]/ul'); Loading Loading
core/modules/navigation/templates/top-bar-page-actions.html.twig +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ {% include 'navigation:toolbar-button' with { text: link['#title'], html_tag: 'a', attributes: create_attribute().setAttribute('href', link['#url']|render|default(null)), attributes: create_attribute(link['#attributes']|default([])).setAttribute('href', link['#url']|render|default(null)), modifiers: ['primary'], icon: featured_page_action.icon, } only %} Loading
core/modules/navigation/tests/navigation_test_top_bar/navigation_test_top_bar.info.yml 0 → 100644 +7 −0 Original line number Diff line number Diff line name: Navigation test top bar description: 'Provides test functionality for top bar in navigation module' package: Testing version: VERSION type: module dependencies: - drupal:navigation
core/modules/navigation/tests/navigation_test_top_bar/src/Plugin/TopBarItem/TopBarItemLinkAttribute.php 0 → 100644 +63 −0 Original line number Diff line number Diff line <?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. */ #[TopBarItem( id: 'test_item_link_attribute', region: TopBarRegion::Actions, label: new TranslatableMarkup('Test Item Link Attribute'), )] 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', ], ], ]; } }
core/modules/navigation/tests/src/Functional/NavigationTopBarTest.php +5 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ class NavigationTopBarTest extends PageCacheTagsTestBase { */ protected static $modules = [ 'navigation', 'navigation_test_top_bar', 'node', 'layout_builder', 'test_page_test', Loading Loading @@ -92,6 +93,10 @@ public function testTopBarVisibility(): void { $this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/a[contains(@class, 'toolbar-button--icon--pencil')]", "Edit"); $this->assertSession()->elementAttributeContains('xpath', "(//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/button)[1]", 'class', 'toolbar-button--icon--dots'); // Verify that the action link contains an extra attribute. $this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/a[contains(@class, 'toolbar-button--icon--database')]", "Test link"); $this->assertSession()->elementAttributeContains('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/a[contains(@class, 'toolbar-button--icon--database')]", 'data-dialog-type', 'modal'); // Find all the dropdown links and check if the top bar is there as well. $toolbar_links = $this->mink->getSession()->getPage()->find('xpath', '//*[@id="top-bar-page-actions"]/ul'); Loading