terminal42 / contao-pageimage

MIT License
12 stars 13 forks source link

Fix array access warnings in templates #56

Closed fritzmg closed 8 months ago

fritzmg commented 11 months ago

Fixes the following warning(s):

ErrorException:
Warning: Undefined array key "hasLink"

  at vendor\terminal42\contao-pageimage\contao\templates\mod_pageimage.html5:6
  at include('vendor\\terminal42\\contao-pageimage\\contao\\templates\\mod_pageimage.html5')
     (vendor\contao\core-bundle\src\Resources\contao\library\Contao\TemplateInheritance.php:108)
aschempp commented 11 months ago

Looking at the code base, hasLink will never be set because it is part of PageImage data but the template only receives data from the figure builder. So maybe we should change that to check for href instead and drop hasLink?

contaoacademy commented 9 months ago

I have the same problem with my installation. I would be pleased if it could be fixed.

fritzmg commented 9 months ago

@contaoacademy can you verify that changing

if ($image['hasLink']):

to

if ($image['href'] ?? null):

works as intended?

contaoacademy commented 9 months ago

The error message has disappeared. However, a link was not displayed. But I get: Warning: Undefined array key "title"

contaoacademy commented 9 months ago

Ok, to clarify I've now run a few more tests.

If I remove the title in the template as a test, I get an output.

To do this, the link must be set via the file manager. If I use the "Overwrite metadata" function, no link is output.

aschempp commented 8 months ago

any updates on the topic? 🙃

fritzmg commented 8 months ago

I did not have time to look into it further unfortunately.

aschempp commented 8 months ago

Fixed in dd9480a5ccf96cde8b9bee2a0f98037fb7ed81bc