繁体   English   中英

Typo3:将 USER_INT 与 HMENU 的 special.value 一起使用

[英]Typo3: Use USER_INT with HMENU's special.value

我只是想在我的page.typoscript文件中使用 PHP 代码以编程方式计算一个值。 这就是我所做的:

        dataProcessing {
            1010 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
            1010 {
                levels = 2
                special = directory
                special.value = USER_INT
                special.value {
                    userFunc = Vendor\Extension\Utils\NavigationBarUtils->getPlatformRootPid
                }
                as = menuMain
            }
         ... 
        }

调用的方法是这个:

    public function getPlatformRootPid(): int
    {
        return 1;
    }

当我加载任何页面时, menuMain为空。 命名空间是正确的。 此外,我已经使用这样的方法来计算同一个page.typoscript文件中的一些其他值,并且它们可以工作。

将该值设置为special.value = 1 ,它会按预期工作。

它是用MenuProcessor的(即HMENU)问题special.value和USER_INT? 他们不知何故不兼容? 还是我在这里错过了其他东西?

非常感谢您!

我想你错过了类型。

special.value需要一个值,该值可能会被.stdWrap函数修改。

您尝试将属性修改为对象,这是行不通的。
您分配了值(字符串) USER_INT和不存在的 stdWrap 函数userFunc

如果你想使用一个对象作为一个值,你需要使用.cObject 所以你的解决方案可能是:

1010 {
    levels = 2
    special = directory
    special.value.cObject = USER_INT
    special.value.cObject {
        userFunc = Vendor\Extension\Utils\NavigationBarUtils->getPlatformRootPid
    }
    as = menuMain
}

最后,我想出了一种方法来做到这一点:

1010 { 
  levels = 2
  special = directory
  special.value.postUserFunc = Vendor\Extension\Utils\NavigationBarUtils->getPlatformRootPid
  as = menuMain 
}

实际上,它完成了我想要的操作,通过调用 PHP 方法以编程方式设置该值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM