简体   繁体   中英

Typo3: Use USER_INT with HMENU's special.value

I'm just trying to compute, in my page.typoscript file, a value programmatically, using PHP code. This is what I've done:

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

And the method called is this one:

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

When I load whatever page menuMain is null. The namespace is correct. Also, I've used methods like this to compute some other values in that same page.typoscript file, and they work.

When setting that value as special.value = 1 , it works as expected.

Is it a problem with MenuProcessor's (ie HMENU) special.value and USER_INT? Are they incompatible somehow? Or am I missing something else here?

Thank you so much in advance!

I think you missed types.

special.value expects a value, which might get modified by .stdWrap functions.

you try to modify an attribute to be an object, which can't work.
you assigned the value (string) USER_INT and the stdWrap function userFunc , which does not exist.

if you want to use an object for a value you need to use .cObject . So your solution probably is:

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

In the end, I've figured out a way to do it:

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

In effect it does what I wanted, set that value programmatically by calling a PHP method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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