You are here

public function TaxonomyMenuHelper::updateTaxonomyMenuEntries in Taxonomy menu 8.3

Update menu entries associate with the vocabulary of this term.

Parameters

\Drupal\taxonomy\TermInterface $term: Term.

bool $rebuild_all: Rebuild all.

File

src/TaxonomyMenuHelper.php, line 95

Class

TaxonomyMenuHelper
Class TaxonomyMenu.

Namespace

Drupal\taxonomy_menu

Code

public function updateTaxonomyMenuEntries(TermInterface $term, $rebuild_all = TRUE) {

  // Load relevant taxonomy menus.
  $tax_menus = $this
    ->getTermMenusByVocabulary($term
    ->bundle());

  /* @var $menu \Drupal\taxonomy_menu\TaxonomyMenuInterface */
  foreach ($tax_menus as $menu) {
    $links = $menu
      ->getLinks([], TRUE);
    foreach ($links as $plugin_id => $plugin_def) {
      if (!$rebuild_all) {
        $plugin_id_explode = explode('.', $plugin_id);
        $term_id = array_pop($plugin_id_explode);
        if ($term
          ->id() != $term_id) {
          continue;
        }
      }
      if ($this->manager
        ->hasDefinition($plugin_id)) {
        $this->manager
          ->updateDefinition($plugin_id, $plugin_def, FALSE);
      }
      else {

        // Remove specific menu link if vid term is different to this old vid.
        if ($term->original
          ->bundle() != $term
          ->bundle()) {
          $this
            ->removeTaxonomyMenuEntries($term->original);
        }
        $this->manager
          ->addDefinition($plugin_id, $plugin_def);
      }
    }
  }
}