class TopBarItemLinkAttribute

Provides a top bar item plugin for testing link attributes in the top bar.

Attributes

#[TopBarItem(id: 'test_item_link_attribute', region: TopBarRegion::Actions, label: new TranslatableMarkup('Test Item Link Attribute'))]

Hierarchy

Expanded class hierarchy of TopBarItemLinkAttribute

File

core/modules/navigation/tests/navigation_test_top_bar/src/Plugin/TopBarItem/TopBarItemLinkAttribute.php, line 17

Namespace

Drupal\navigation_test_top_bar\Plugin\TopBarItem
View source
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',
        ],
      ],
    ];
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable Deprecated public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 80
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1
TopBarItemBase::label public function Returns the translated plugin label. Overrides TopBarItemPluginInterface::label
TopBarItemBase::region public function Returns the plugin region. Overrides TopBarItemPluginInterface::region
TopBarItemLinkAttribute::build public function Builds and returns the renderable array for this top bar item plugin. Overrides TopBarItemBase::build

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