Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FalViewHelper throw an error when the record is hidden #1714

Open
olinox14 opened this issue Mar 29, 2021 · 2 comments
Open

FalViewHelper throw an error when the record is hidden #1714

olinox14 opened this issue Mar 29, 2021 · 2 comments

Comments

@olinox14
Copy link

olinox14 commented Mar 29, 2021

Issue: an exception No record was found. The "record" or "uid" argument must be specified. is thrown when using FalViewHelper within an hidden content.
To reproduce, create a template:

{namespace v=FluidTYPO3\Vhs\ViewHelpers}
{namespace flux=FluidTYPO3\Flux\ViewHelpers}

<div xmlns="http://www.w3.org/1999/xhtml"
     xmlns:flux="http://fedext.net/ns/flux/ViewHelpers"
     xmlns:v="http://fedext.net/ns/vhs/ViewHelpers"
     xmlns:f="http://typo3.org/ns/fluid/ViewHelpers">

    <f:section name="Configuration">
        <flux:form id="Carousel" label="My Carousel" extensionName="my_extension">
            <flux:field.inline.fal name="images" minItems="2" maxItems="24"/>
        </flux:form>
    </f:section>
    <f:section name="Preview">
            <f:for each="{v:content.resources.fal(field: 'images', uid: '{record.uid}')}"
                   as="image"
                   iteration="iterator">
                    <f:image treatIdAsReference="1"
                             src="{image.id}"
                             title="{image.title}"
                             alt="{image.alternative}"
                    />
            </f:for>
    </f:section>
</div>

Then, add a content of this type to a page in the Typo3 Backend, and hide this content.

An exception is thrown, because the FluidTYPO3\Vhs\ViewHelpers\Resource\Record\AbstractRecordResourceViewHelper->getRecord() can not find any matching record (default restrictions apply to querybuilder here)

A quick workaround is to replace:
{v:content.resources.fal(field: 'images', uid: '{record.uid}')}
By
{v:content.resources.fal(field: 'images', record: '{record}')}

However, this remains a bug, and I suggest to remove the 'HiddenRestriction' from the querybuilder in the getRecord() method. Maybe StartTimeRestriction and EndTimeRestriction shall be removed too.

@NamelessCoder
Copy link
Member

Since this ViewHelper is designed for frontend usage, it is not sensible to remove the display restrictions (neither hidden nor others). The right solution is actually the workaround you already came up with - passing the record so the ViewHelper does not attempt to load it. In fact this is also recommended practice in frontend for any use case where you have access to the page/content record (Flux will attempt to insert this into template variables but non-Flux usage may not have access to the record). This is also better for performance since you don't cause an unnecessary SQL query (actually, one additional query per relation).

@olinox14
Copy link
Author

I use this VH in the backend to display a preview of the carousel images, shouldn't I?
I agree on the fact that it's obviously better to directly pass the record, however I don't think that the sole fact of passing the uid as parameter should be able to crash the backend because of an hidden content... The exception could be catch and managed in the viewhelper, or as I said, the restrictions could be lifted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants