You are here

public function MenuPosition::evaluate in Menu Condition 8

Evaluates the condition and returns TRUE or FALSE accordingly.

Return value

bool TRUE if the condition has been met, FALSE otherwise.

Overrides ConditionInterface::evaluate

File

src/Plugin/Condition/MenuPosition.php, line 85

Class

MenuPosition
Provides a 'Menu position' condition.

Namespace

Drupal\menu_condition\Plugin\Condition

Code

public function evaluate() {
  if (empty($this->configuration['menu_parent'])) {
    return TRUE;
  }
  list($menu_name, $link_plugin_id) = explode(':', $this->configuration['menu_parent'], 2);
  $active_trail_ids = $this->menuActiveTrail
    ->getActiveTrailIds($menu_name);

  // The condition evaluates to TRUE if the given menu link is in the active
  // trail.
  if ($link_plugin_id) {
    return isset($active_trail_ids[$link_plugin_id]);
  }
  else {

    // Condition for when a whole menu was selected.
    return (bool) array_filter($active_trail_ids);
  }
}