You are here

public function TaxonomyMenuHelper::generateTaxonomyMenuEntries in Taxonomy menu 8.3

Create 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 64

Class

TaxonomyMenuHelper
Class TaxonomyMenu.

Namespace

Drupal\taxonomy_menu

Code

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

  // Load relevant taxonomy menus.
  $tax_menus = $this
    ->getTermMenusByVocabulary($term
    ->bundle());
  foreach ($tax_menus as $menu) {
    foreach ($menu
      ->getLinks([], TRUE) as $plugin_id => $plugin_def) {
      if (!$rebuild_all) {
        $plugin_id_parts = explode('.', $plugin_id);
        $term_id = array_pop($plugin_id_parts);
        if ($term
          ->id() != $term_id) {
          continue;
        }
      }
      if ($this->manager
        ->hasDefinition($plugin_id)) {
        $this->manager
          ->updateDefinition($plugin_id, $plugin_def);
      }
      else {
        $this->manager
          ->addDefinition($plugin_id, $plugin_def);
      }
    }
  }
}