- Issue created by @euk
- π¨π΄Colombia camilo.escobar
I could reproduce this issue when using the "FlexSlider (Entity view)" field formatter on an entity reference field.
In such a case, the$variables['item']
that arrives totemplate_preprocess_flexslider_list_item(&$variables)
is the render array of the referenced entity, something like the following:array:6 [βΌ "#paragraph" => Drupal\paragraphs\Entity\Paragraph {#4178 βΆ} "#view_mode" => "default" "#cache" => array:3 [βΆ] "#theme" => "paragraph" "#weight" => 0 "#pre_render" => array:1 [βΆ] ]
In other cases, as for example when the FlexSlider is selected as the display option from a View,
$variables['item']
here will contain HTML markup (I assume it undergoes the rendering pipeline in an earlier state).Hence, when the entity render array above is attempted to be passed to
preg_match()
:if (!preg_match("/<img.+?src=[\"'](.+?)[\"'].+?>/", $item, $src)) { preg_match("/<img.+?srcset=[\"'](.+?)[\"'].+?>/", $item, $src); }
PHP triggers the error:
TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in preg_match() (line 155 of modules/contrib/flexslider/templates/flexslider.theme.inc).
I assume this could be "easily solved" if we first render the array to get its resulting markup, before it undergoes the
preg_match()
, something like this:if (is_array($item)) { $item = \Drupal::service('renderer')->renderRoot($item); }
At least it would avoid the
preg_match(): Argument #2
error.However, I feel that grabbing the URL of the thumbnail image from the
src
attribute of a<img />
tag detected via a regular expression is not the best way to provide support for thumbnail images. It is like a very odd and random way to pick the thumbnails up.As a desired enhancement, I'd like to propose that the "FlexSlider (Entity view)" Field Formatter has a new configuration option to select the field from the entity in question from where the thumbnail image must be taken. And the same for the FlexSlider View's display.
- πΊπΈUnited States euk
It's been a while since I looked at that, but if we are to pull a thumbnail image - why not from the originally referenced media? with some option to choose what image style to use...
Bumped to major because media thumbnails are broken too.
Maybe the work from the referenced issue should be rolled together.