FluidTYPO3 / vhs

TYPO3 extension VHS: Fluid ViewHelpers
https://fluidtypo3.org
Other
190 stars 229 forks source link

TYPO3 11: InfoViewHelper does not work in backend context without a simulated frontend. #1730

Closed Abdull closed 2 years ago

Abdull commented 2 years ago

Using

"typo3/cms-*": "-11.3.1"
"fluidtypo3/vhs": "dev-development"

My TYPO3 frontend pages are configured with a Fluid layout using <v:page.header.title title="{v:page.info(field:'title')}" />

When visiting the frontend with a TYPO3 template using , the following exception occurs:

1/1) #1489931508 TYPO3Fluid\Fluid\Core\ViewHelper\Exception

ViewHelper FluidTYPO3\Vhs\ViewHelpers\Page\InfoViewHelper does not work in backend context without a simulated frontend.
in /var/www/typo3/public/typo3conf/ext/vhs/Classes/Utility/ErrorUtility.php line 25

     */
    public static function throwViewHelperException($message = null, $code = null)
    {
        if (version_compare(TYPO3_version, '8.0', '>=')) {
            throw new \TYPO3Fluid\Fluid\Core\ViewHelper\Exception($message, $code);
        }
        throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception($message, $code);
    }
}

at FluidTYPO3\Vhs\Utility\ErrorUtility::throwViewHelperException()
in /var/www/typo3/public/typo3conf/ext/vhs/Classes/ViewHelpers/Page/InfoViewHelper.php line 67

    ) {
        if (!isset($GLOBALS['TSFE']) || !$GLOBALS['TSFE']->sys_page instanceof PageRepository) {
            ErrorUtility::throwViewHelperException(
                sprintf('ViewHelper %s does not work in backend context without a simulated frontend.', static::class),
                1489931508
            );
        }
        $pageUid = (integer) $arguments['pageUid'];
        if (0 === $pageUid) {

at FluidTYPO3\Vhs\ViewHelpers\Page\InfoViewHelper::renderStatic()
in /var/www/typo3/vendor/typo3fluid/fluid/src/Core/ViewHelper/Traits/CompileWithRenderStatic.php line 30

    {
        return static::renderStatic(
            $this->arguments,
            $this->buildRenderChildrenClosure(),
            $this->renderingContext
        );
    }

    /**

at FluidTYPO3\Vhs\ViewHelpers\Page\InfoViewHelper->render()
at call_user_func()
in /var/www/typo3/vendor/typo3fluid/fluid/src/Core/ViewHelper/AbstractViewHelper.php line 264

     */
    protected function callRenderMethod()
    {
        if (method_exists($this, 'render')) {
            return call_user_func([$this, 'render']);
        }
        if ((new \ReflectionMethod($this, 'renderStatic'))->getDeclaringClass()->getName() !== AbstractViewHelper::class) {
            // Method is safe to call - will not recurse through ViewHelperInvoker via the default
            // implementation of renderStatic() on this class.

at TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper->callRenderMethod()
in /var/www/typo3/vendor/typo3fluid/fluid/src/Core/ViewHelper/AbstractViewHelper.php line 252

...

So if I assume correctly, $GLOBALS['TSFE'] is not set, even though the request is in a frontend context.

Any ideas?

This exception does not occur for me in TYPO3 10.

CreativDesigner commented 2 years ago

Unfortunately the message is a bit wrong, $GLOBALS['TSFE'] is set. The problem is with the !$GLOBALS['TSFE']->sys_page instanceof PageRepository. The PageRepository namespace in line 13 has changed in Typo3 11 from TYPO3\CMS\Frontend\Page\PageRepository to TYPO3\CMS\Core\Domain\Repository\PageRepository. This change solved the problem for me.

smichaelsen commented 2 years ago

TYPO3\CMS\Frontend\Page\PageRepository is used in several places in the code and they all fail with TYPO3 v11. I don't know what is the proper way solve this in EXT:vhs and maintain compatibility with < v11.

typo3ua commented 2 years ago

Unfortunately the message is a bit wrong, $GLOBALS['TSFE'] is set. The problem is with the !$GLOBALS['TSFE']->sys_page instanceof PageRepository. The PageRepository namespace in line 13 has changed in Typo3 11 from TYPO3\CMS\Frontend\Page\PageRepository to TYPO3\CMS\Core\Domain\Repository\PageRepository. This change solved the problem for me.

Me too...

Thanks!

hacksch commented 2 years ago

Duplicate Issue with pull requests https://github.com/FluidTYPO3/vhs/issues/1737