loadLinks example


  public function loadTreeData($menu_name, MenuTreeParameters $parameters) {
    $tree_cid = "tree-data:$menu_name:" . serialize($parameters);
    $cache = $this->menuCacheBackend->get($tree_cid);
    if ($cache && isset($cache->data)) {
      $data = $cache->data;
      // Cache the definitions in memory so they don't need to be loaded again.       $this->definitions += $data['definitions'];
      unset($data['definitions']);
    }
    else {
      $links = $this->loadLinks($menu_name$parameters);
      $data['tree'] = $this->doBuildTreeData($links$parameters->activeTrail, $parameters->minDepth);
      $data['definitions'] = [];
      $data['route_names'] = $this->collectRoutesAndDefinitions($data['tree']$data['definitions']);
      $this->menuCacheBackend->set($tree_cid$data, Cache::PERMANENT, ['config:system.menu.' . $menu_name]);
      // The definitions were already added to $this->definitions in       // $this->doBuildTreeData()       unset($data['definitions']);
    }
    return $data;
  }

  
    // include it in the cache ID.     if ($active_workspace = $this->workspaceManager->getActiveWorkspace()) {
      $parameters->conditions['workspace'] = $active_workspace->id();
    }
    return parent::loadTreeData($menu_name$parameters);
  }

  /** * {@inheritdoc} */
  protected function loadLinks($menu_name, MenuTreeParameters $parameters) {
    $links = parent::loadLinks($menu_name$parameters);

    // Replace the menu link plugin definitions with workspace-specific ones.     if ($active_workspace = $this->workspaceManager->getActiveWorkspace()) {
      $tracked_revisions = $this->workspaceAssociation->getTrackedEntities($active_workspace->id());
      if (isset($tracked_revisions['menu_link_content'])) {
        /** @var \Drupal\menu_link_content\MenuLinkContentInterface[] $workspace_revisions */
        $workspace_revisions = $this->entityTypeManager->getStorage('menu_link_content')->loadMultipleRevisions(array_keys($tracked_revisions['menu_link_content']));
        foreach ($workspace_revisions as $workspace_revision) {
          if (isset($links[$workspace_revision->getPluginId()])) {
            $pending_plugin_definition = $workspace_revision->getPluginDefinition();
            $links[$workspace_revision->getPluginId()] = [
              
Home | Imprint | This part of the site doesn't use cookies.