You are here

protected function Tracker::setTrackedMenus in Menu Entity Index 8

Sets menus to track and updates database table accordingly.

Parameters

array $menus: Menu names to track.

bool $force: Retrack all tracked menus, even, if menu configuration didn't change. Default is FALSE.

1 call to Tracker::setTrackedMenus()
Tracker::setConfiguration in src/Tracker.php
Sets configuration values and triggers rescanning of menus as needed.

File

src/Tracker.php, line 274

Class

Tracker
Tracks menu links and their referenced entities.

Namespace

Drupal\menu_entity_index

Code

protected function setTrackedMenus(array $menus = [], $force = FALSE) {
  $old_values = $this
    ->getTrackedMenus();
  $this->configFactory
    ->getEditable('menu_entity_index.configuration')
    ->set('all_menus', FALSE)
    ->set('menus', $menus)
    ->save();
  $this->config = $this->configFactory
    ->get('menu_entity_index.configuration');
  if ($force) {

    // If we force a rebuild, make sure we untrack all existing indexed items.
    $this
      ->untrackMenus(array_keys($this
      ->getAvailableMenus()));
    $this
      ->trackMenus($this
      ->getTrackedMenus());
  }
  else {
    $new_menus = (array) array_diff($menus, $old_values);
    $this
      ->untrackMenus((array) array_diff($old_values, $menus));
    $this
      ->trackMenus($new_menus);
  }
}