function NavigationLinkBlockTest::appendNavigationLinkBlock

Adds a Navigation Link Block to the sidebar.

Parameters

string $label: The block label.

string $link_title: The link title.

string $link_uri: The link uri.

string $link_icon: The link icon CSS class.

2 calls to NavigationLinkBlockTest::appendNavigationLinkBlock()
NavigationLinkBlockTest::testNavigationLinkBlockCache in core/modules/navigation/tests/src/Functional/NavigationLinkBlockTest.php
Test output of the link navigation with regards to caching and contents.
NavigationLinkBlockTest::testNavigationLinkBlockVisibility in core/modules/navigation/tests/src/Functional/NavigationLinkBlockTest.php
Test block visibility based on the link access logic.

File

core/modules/navigation/tests/src/Functional/NavigationLinkBlockTest.php, line 207

Class

NavigationLinkBlockTest
Tests for \Drupal\navigation\Plugin\Block\NavigationLinkBlockTest.

Namespace

Drupal\Tests\navigation\Functional

Code

protected function appendNavigationLinkBlock(string $label, string $link_title, string $link_uri, string $link_icon) : void {
  $section_storage_manager = \Drupal::service('plugin.manager.layout_builder.section_storage');
  $cacheability = new CacheableMetadata();
  $contexts = [
    'navigation' => new Context(ContextDefinition::create('string'), 'navigation'),
  ];
  /** @var \Drupal\layout_builder\SectionListInterface $section_list */
  $section_list = $section_storage_manager->findByContext($contexts, $cacheability);
  $section = $section_list->getSection(0);
  $section->appendComponent(new SectionComponent(\Drupal::service('uuid')->generate(), 'content', [
    'id' => 'navigation_link',
    'label' => $label,
    'label_display' => '1',
    'provider' => 'navigation',
    'context_mapping' => [],
    'title' => $link_title,
    'uri' => $link_uri,
    'icon_class' => $link_icon,
  ]));
  $section_list->save();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.