Contao: Predefined image sizes do not work in some modules

Created on 30 Jan 2020  Â·  3Comments  Â·  Source: contao/contao

When using a predefined image size (https://github.com/contao/contao/pull/537), the teaser images of the ModuleNewsList will not be resized accordingly. Instead, only the original image will be shown.

The problem is this condition:

https://github.com/contao/contao/blob/feda301a54a68920d2b5be38f6a13b8641aa211b/news-bundle/src/Resources/contao/modules/ModuleNews.php#L178-L181

None of the conditions will be true, since the size array will look like this:

[
  0 => "",
  1 => "",
  2 => "_foobar",
]

With the new predefined image sizes, none of the parameters will be numeric.

This problem exists in the following classes, as far as I can see:

  • ModuleNews
  • ModuleEventList
  • ModuleEventReader

I am not sure what the correct fix is. May be add a fourth condition?

if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2]) || strpos($size[2], '_') === 0)

Are these checks needed at all actually? Doesn't the image factory handle all cases by itself anyway?

This affects Contao 4.8 and 4.9.

bug

Most helpful comment

Are these checks needed at all actually?

I think so, yes. $arrArticle['size'] should only get overwritten if $this->imgSize is a “real” size.

For backwards compatibility sizes like [0, 0, 'proportional'] need to be handled the same way as if they are not set at all.

All 3 comments

Are these checks needed at all actually?

I think so, yes. $arrArticle['size'] should only get overwritten if $this->imgSize is a “real” size.

For backwards compatibility sizes like [0, 0, 'proportional'] need to be handled the same way as if they are not set at all.

So how do we fix the issue?

I am not sure what the correct fix is. May be add a fourth condition?

As discussed on Mumble, yes.

($size[2][0] ?? null) === '_' should be the most performant way for the check, see https://3v4l.org/77aKk

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alibi-Contao picture Alibi-Contao  Â·  3Comments

theDyingMountain picture theDyingMountain  Â·  4Comments

issue-bot picture issue-bot  Â·  4Comments

Mynyx picture Mynyx  Â·  3Comments

m-vo picture m-vo  Â·  3Comments