使用扩展记录扩展 HMENU

Extending HMENU with extensions records

在我的扩展中有类别和产品。我希望类别显示为子菜单。

我的页面树是这样的:

在页面 "Clothes" (uid: 2) 和 "Workwear" (uid: 4) 上,我有一个插件可以显示类别和产品。

要显示的类别在 TS 设置中定义(每个页面上都有一个 ext+ 模板),如下所示:

plugin.tx_productsdb.settings.categories = 1,2,3,4

我的子导航的拼写错误如下所示:

nav.subnavigation = COA
nav.subnavigation {

  10 = HMENU
  10 {
    entryLevel = 0

    1 = TMENU
    1 {
      wrap = <ul>|</ul>
      NO = 0
      NO.wrapItemAndSub = <li class="first">|</li> |*| <li>|</li> |*| <li class="last">|</li>

      ACT = 1
      ACT.wrapItemAndSub = <li class="active first">|</li> |*| <li class="active">|</li> |*| <li class="active last">|</li>
      ACT.ATagParams = class="active"

      CUR < .ACT
    }
    2 < .1
    2.wrap = <ul class="level2">|</ul>
    3 < .1
    3.wrap = <ul class="level3">|</ul>
  }
}

我已经尝试使用 HMENU 的 itemArrayProcFunc 属性,但是我找不到关于如何将它与我的命名空间扩展一起使用的示例。

我试过这个:

  10 = HMENU
  10 {
    entryLevel = 0
    itemArrayProcFunc = Vendor\Extension\Hooks\Subnavigation->process

函数如下:

class Subnavigation
{
    /**
     * @param $menuArr
     * @param $conf
     */
    public function process(&$menuArr, &$conf)
    {
        // show me, that something is happening here ... pretty please!
        \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($menuArr);
        exit;
    }
}

如果您有任何关于如何操作的示例,请告诉我。 提前致谢。

我有一个包含产品和类别的项目。 类别应该显示在菜单中,我通过调用 AJAX 方法的 JavaScript 解决了它。 AJAX 方法调用预定义的页面类型,例如index.php?id=xx&type=xx

TypoScript 看起来像这样:

menuItems = PAGE
menuItems.typeNum = xx
menuItems {
    config {
        disableAllHeaderCode = 1
        no_cache = 1
    }
    10 = USER_INT
    10.userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    10 {
        extensionName = ExtensionName
        pluginName = Plugin
        vendorName = Vendor
        controller = Product
        action = getMenu
        switchableControllerActions {
            Product {
                1 = getMenu
            }
        }
        view < plugin.tx_plugin.view
        persistence < plugin.tx_plugin.persistence
        settings < plugin.tx_plugin.settings
    }
}

控制器动作如下所示:

/**
 * @return void
 */
public function getMenuAction()
{
    $menuItems = [];
    $categories = $this->categoryRepository->findAll();
    foreach ($categories as $category) {
        /** @var Category $category */
        $menuItems[] = [
            'name' => $category->getTitle(),
            'link' => $this->getLinkForCategory($category),
            'id' => $category->getUid()
        ];
    }

    $this->view->assign('menuItems', $menuItems);
    echo $this->view->render();
    exit;
}

在 Fluid 中,您只需为菜单创建

  • 结构。

  • 最后,在多次失败的尝试之后,我放弃了我使用itemArrayProcFunc的方法。

    我的解决方案与 Thomas 发布的解决方案有一些相似之处。

    我正在使用 TS 条件并完全自行构建导航。

    [PIDinRootline = 2] || [PIDinRootline = 3]
    lib.subnav >
    lib.subnav = USER_INT
    lib.subnav {
      userFunc       = TYPO3\CMS\Extbase\Core\Bootstrap->run
      vendorName     = Vendor
      extensionName  = ExtensionName
      pluginName     = pluginName
      controller     = Controller
      action         = getSubnavigation
    
      view < plugin.tx_plugin.view
      persistence < plugin.tx_plugin.persistence
      settings < plugin.tx_plugin.settings
    }
    [global]
    

    我的控制器动作:

    public function getSubnavigationAction()
    {
    
        $rootline = $this->pageRepository->getRootLine($GLOBALS['TSFE']->id);
    
        // assumption: main page is always on level 1
        $rootId = $rootline[1]['uid'];
        $treePids = $this->getTreePids($rootId);
        $pages = $this->pageRepository->getMenuForPages($treePids, 'uid, pid, title', 'sorting', ' AND hidden=0 AND deleted=0');
        $rootPage = $pages[$rootId];
    
        $tree = $this->buildTree($rootPage, $pages);
        $menu = $this->buildMenu($tree);
    
        $current = $this->argumentService->getArgument('tx_productsdb_categories', 'category');
        $parent = 0;
        if($this->argumentService->hasArgument('tx_productsdb_categories', 'parent')) {
            $parent = $this->argumentService->getArgument('tx_productsdb_categories', 'parent');
        }
    
        $this->view->assign('parent', $parent);
        $this->view->assign('current', $current);
        $this->view->assign('menu', $menu);
        $this->view->assign('settings', $this->settings);
    }
    

    然后在 Fluid 中构建菜单。