使用扩展记录扩展HMENU

时间:2017-02-19 16:06:33

标签: typo3 typo3-7.6.x

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

我的页面树看起来像这样:

  • 主页
  • 衣服(uid:2)
  • 特别优惠(uid:3)
    • 工作服(uid:4)

在页面"衣服" (uid:2)和"工作服" (uid:4)我有一个插件,可以显示类别和产品。

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

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

我的子导航的typoscript看起来像这样:

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;
    }
}

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

2 个答案:

答案 0 :(得分:0)

我有一个包含产品和类别的项目。 类别应该显示在菜单中,我通过调用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中你只需要为菜单创建

  • 结构。

  • 答案 1 :(得分:0)

    最后,经过多次尝试失败后,我放弃我的方法 itemArrayProcFunc

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

    我正在使用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中构建菜单。

    相关问题