FluidTYPO3 / vhs

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

"v:content.resources.fal" in TYPO3 v11 in a flux template "Preview" section causes "No aspect named "frontend.preview" found." Errror #1796

Open ako-3004 opened 1 year ago

ako-3004 commented 1 year ago

Affects TYPO3 v11.5.13 with flux (9.6.1) and vhs (6.1.2) it is not possible to use "v:content.resources.fal" in a flux content template in the "preview" section:

Flux Content Template:

<f:section name="Preview">
    <f:debug>{v:content.resources.fal(table:'tt_content', field: 'settings.teaser.image', uid: '594')}</f:debug>
</f:section>

causes error:

(1/1) #1527777868 TYPO3\CMS\Core\Context\Exception\AspectNotFoundException No aspect named "frontend.preview" found.

So, missing frontend.preview aspect in /var/www/mbcs/public/typo3conf/ext/vhs/Classes/ViewHelpers/Resource/Record/AbstractRecordResourceViewHelper.php line 173

lines 171 to 176:

if (class_exists('\\TYPO3\\CMS\\Frontend\\Aspect\\PreviewAspect')) {
    //TYPO3 version >= 10
    $fePreview = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.preview', 'isPreview');
} else {
    $fePreview = (bool)(isset($GLOBALS['TSFE']) && $GLOBALS['TSFE']->fePreview);
}

guess "frontend.preview" is for real frontend preview in TYPO3 backend, but not for the preview section. Aspect "frontend.preview" does not exist in TYPO3\CMS\Core\Context\Context

this may be the solution:

if (class_exists('\\TYPO3\\CMS\\Frontend\\Aspect\\PreviewAspect')) {
    //TYPO3 version >= 10
    if (GeneralUtility::makeInstance(Context::class)->hasAspect('frontend.preview')) {
        $fePreview = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.preview', 'isPreview');  
    } else {
        $fePreview = false;
    }
} else {
    $fePreview = (bool)(isset($GLOBALS['TSFE']) && $GLOBALS['TSFE']->fePreview);
}
shroom24 commented 1 year ago

replacing

{v:content.resources.fal(table: 'tt_content', field: 'images', record.uid: uid)}

with

{v:content.resources.fal(table: 'tt_content', field: 'images', record: record)}

solved the error for me

OliverRWeiss commented 1 year ago

This problem also arises with {v:resource.record()} when used in TYPO3 backend. @ako-3004 's solution fixes the error.