You are here

protected function MenuTrailByPathActiveTrail::doGetActiveTrailIds in Menu Trail By Path 8

Helper method for ::getActiveTrailIds().

Overrides MenuActiveTrail::doGetActiveTrailIds

File

src/MenuTrailByPathActiveTrail.php, line 101

Class

MenuTrailByPathActiveTrail
Overrides the class for the file entity normalizer from HAL.

Namespace

Drupal\menu_trail_by_path

Code

protected function doGetActiveTrailIds($menu_name) {

  // Parent ids; used both as key and value to ensure uniqueness.
  // We always want all the top-level links with parent == ''.
  $active_trail = array(
    '' => '',
  );
  $entity = Menu::load($menu_name);
  if (!$entity) {
    return $active_trail;
  }

  // Build an active trail based on the trail source setting.
  $trail_source = $entity
    ->getThirdPartySetting('menu_trail_by_path', 'trail_source') ?: $this->config
    ->get('trail_source');
  if ($trail_source == static::MENU_TRAIL_CORE) {
    return parent::doGetActiveTrailIds($menu_name);
  }
  elseif ($trail_source == static::MENU_TRAIL_DISABLED) {
    return $active_trail;
  }

  // If a link in the given menu indeed matches the path, then use it to
  // complete the active trail.
  if ($active_link = $this
    ->getActiveTrailLink($menu_name)) {
    if ($parents = $this->menuLinkManager
      ->getParentIds($active_link
      ->getPluginId())) {
      $active_trail = $parents + $active_trail;
    }
  }
  return $active_trail;
}