function SystemMenuBlock::shouldSetActiveTrail

Determine whether the menu block should set active trails on the links.

The active trail must be set if it's required to build the correct set of links, so setting 'ignore_active_trail' to TRUE only works with certain configurations:

  • The initial level is 1 and all items are expanded
  • The initial level is 1 and only 1 level of links are displayed

While the form UI and validation should prevent 'ignore_active_trail' from being set to TRUE otherwise, the other settings are checked as well, in case the configuration is somehow in an invalid state.

Return value

bool TRUE if the menu block should set active trails on the links.

2 calls to SystemMenuBlock::shouldSetActiveTrail()
SystemMenuBlock::build in core/modules/system/src/Plugin/Block/SystemMenuBlock.php
Builds and returns the renderable array for this block plugin.
SystemMenuBlock::getCacheContexts in core/modules/system/src/Plugin/Block/SystemMenuBlock.php

File

core/modules/system/src/Plugin/Block/SystemMenuBlock.php, line 314

Class

SystemMenuBlock
Provides a generic Menu block.

Namespace

Drupal\system\Plugin\Block

Code

protected function shouldSetActiveTrail() : bool {
  return empty($this->configuration['ignore_active_trail']) || $this->configuration['level'] !== 1 || empty($this->configuration['expand_all_items']) && $this->configuration['depth'] !== 1;
}

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