You are here

public function TaxonomyMenu::getLinks in Taxonomy menu 8.3

Get menu link plugin definitions.

Parameters

array $base_plugin_definition: Base plugin deifinition.

bool $include_base_plugin_id: If true, 'taxonomy_menu.menu_link:' will be prepended to the returned plugin ids.

Return value

array Associative array of menu links ids and definitions.

Overrides TaxonomyMenuInterface::getLinks

2 calls to TaxonomyMenu::getLinks()
TaxonomyMenu::delete in src/Entity/TaxonomyMenu.php
Deletes an entity permanently.
TaxonomyMenu::save in src/Entity/TaxonomyMenu.php
Saves an entity permanently.

File

src/Entity/TaxonomyMenu.php, line 198

Class

TaxonomyMenu
Defines the TaxonomyMenu entity.

Namespace

Drupal\taxonomy_menu\Entity

Code

public function getLinks(array $base_plugin_definition = [], $include_base_plugin_id = FALSE) {

  /* @var $termStorage \Drupal\taxonomy\TermStorageInterface */
  $termStorage = $this
    ->entityTypeManager()
    ->getStorage('taxonomy_term');

  // Load taxonomy terms for tax menu vocab.
  $terms = $termStorage
    ->loadTree($this
    ->getVocabulary(), 0, $this
    ->getDepth() + 1);
  $links = [];

  // Create menu links for each term in the vocabulary.
  foreach ($terms as $term) {
    if (!$term instanceof TermInterface) {
      $term = Term::load($term->tid);
    }
    $mlid = $this
      ->buildMenuPluginId($term, $include_base_plugin_id);
    $links[$mlid] = $this
      ->buildMenuDefinition($term, $base_plugin_definition);
  }
  return $links;
}