You are here

public function CheeseburgerMenuItem::applySettings in Cheeseburger Menu 5.0.x

Applies given settings to menu item.

Parameters

array $settings: An associative array containing:

  • parent_as_link: A boolean indicating is parent menu item link. Defaults to FALSE.
  • expanded: A boolean indicating that menu item is expanded. Defaults to FALSE.
  • active_trail: A array with current active trail. Defaults to empty array.

File

src/CheeseburgerMenuItem.php, line 367

Class

CheeseburgerMenuItem
Cheeseburger menu item class.

Namespace

Drupal\cheeseburger_menu

Code

public function applySettings(array $settings) {
  static::applyDefaultMenuSettings($settings);
  if ($settings['parent_as_link']) {
    $this
      ->setIsLink(TRUE);
  }
  elseif ($this
    ->hasChild()) {
    $this
      ->setIsLink(FALSE);
  }
  if ($settings['expanded']) {
    $this
      ->getAttribute()
      ->addClass('cheeseburger-menu__item--is-expanded')
      ->setAttribute('data-cheeseburger-default-expand', '');
  }
  else {
    $this
      ->getAttribute()
      ->removeClass('cheeseburger-menu__item--is-expanded');
  }
  if ($this
    ->hasChild()) {
    $this
      ->getAttribute()
      ->addClass('cheeseburger-parent');
  }
  else {
    $this
      ->getAttribute()
      ->removeClass('cheeseburger-parent');
  }
  return $this;
}