FluidTYPO3 / vhs

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

BUG: Argument #1 ($src) must be of type string #1908

Open DanYouCan opened 2 weeks ago

DanYouCan commented 2 weeks ago

I have upgraded TYPO3 from version 9 (vhs V6.1.3) to 12 vhs V7.0.3. With V12 I got the following error:

FluidTYPO3\Vhs\ViewHelpers\Media\ImageViewHelper::getImgResource(): Argument #1 ($src) must be of type string, TYPO3\CMS\Core\Resource\FileReference given, called in /html/typo3-upgr/typo3conf/ext/vhs/Classes/Traits/SourceSetViewHelperTrait.php on line 48

For that my frontend fluid code was (it was taken over from V9):

<v:media.image
  src="{file}"
  width="{dimensions.width}"
  height="{dimensions.height}"
  alt="{file.alternative}"
  title="{file.title}"
  class="image-embed-item"
  treatIdAsReference="true"
  srcset="576,768,992,1200,1900"
  srcsetDefault="768"
  additionalAttributes = "{loading : 'lazy'}"
  quality="75"
/>

After debugging and trial I ended up with following working code:

<v:media.image
  src="/fileadmin/{file.originalFile.identifier}"
  width="{dimensions.width}"
  height="{dimensions.height}"
  alt="{file.alternative}"
  title="{file.title}"
  class="image-embed-item"
  treatIdAsReference="true"
  srcset="576,768,992,1200,1900"
  srcsetDefault="768"
  additionalAttributes = "{loading : 'lazy'}"
  quality="75"
/>

So it looks like this view helper in vhs V7.0.3 can no longer handle objects like {file}? Is this intentional? Thank you in advance for checking my statement.

NamelessCoder commented 4 hours ago

Untested, but if this worked in earlier versions then it's possible that the object was automatically converted from File(Reference) to string, in which case it might work for you if you use src="{file as string}" (fluid's type casting mechanism).

It is correct that this ViewHelper does not support File(Reference) instances and never did (except possibly by coincidence). Recent changes have made this constraint a formal constraint by using strict type hints for arguments where before, it's possible the methods may have silently accepted a File(Reference) instance and simply converted it to a string internally.