You are here

public function TaxonomyMenuHelper::removeTaxonomyMenuEntries in Taxonomy menu 8.3

Remove menu entries associate with the vocabulary of this term.

Parameters

\Drupal\taxonomy\TermInterface $term: Term.

bool $rebuild_all: Whether to rebuild all links or not.

1 call to TaxonomyMenuHelper::removeTaxonomyMenuEntries()
TaxonomyMenuHelper::updateTaxonomyMenuEntries in src/TaxonomyMenuHelper.php
Update menu entries associate with the vocabulary of this term.

File

src/TaxonomyMenuHelper.php, line 135

Class

TaxonomyMenuHelper
Class TaxonomyMenu.

Namespace

Drupal\taxonomy_menu

Code

public function removeTaxonomyMenuEntries(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) {

    // Remove all links.
    if ($rebuild_all) {
      $links = array_keys($menu
        ->getLinks([], TRUE));
      foreach ($links as $plugin_id) {
        $this->manager
          ->removeDefinition($plugin_id, FALSE);
      }
    }
    elseif (!empty($term)) {
      $this->manager
        ->removeDefinition($menu
        ->buildMenuPluginId($term), FALSE);
    }
  }
}