Replace twig_tweak's drupal_image() where possible by drupal_field()

Created on 11 May 2023, over 1 year ago
Updated 17 October 2023, over 1 year ago

Problem/Motivation

Based on the twig_tweak drupal_image() complications found in 🐛 drupal_image() needs #width / #height values for fully working image cache scale, lazy-loading and img attributes RTBC we should discuss if it's possible and more stable to replace large parts of our custom code by utilizing field formatters on the image field, using drupal_field() with a display formatter array instead.

That way we could utilize all existing image formatters (responsive, photoswipe, ...) and their settings (as array).

Due to the genius implementation of flexible_image.html.twig and its parameters, this should already be possible in large parts.

This is where drupal_image() is used in this module:
https://git.drupalcode.org/search?search=drupal_image&nav_source=navbar&...

We should first have a look if it's possible and what's possible and play around a bit, my hope would be the following improvements:

  • Less risk of custom logic using drupal_image() with it's discussable custom implementation
  • Automatically solving things like "alt" attribute, further attributes, libraries etc. indirectly via the field formatter magically
  • Better caching through Drupal fields itself (performance) - @Chi already mentioned that might be a harder issue with drupal_image() and imagecache calculations at runtime
  • Being able to utilize what's implemented in the different field formatters already without having to initialize photoswipe ourselves etc.

=> More stable implementation in general!

If Allow custom URL() to be used for image fields Active is finished, we could even use the "image_link" setting to link the image to arbitrary URLs. That should be pushed forward then.

In drowl_media we were already able to solve this: 🐛 Replace twig_tweak's drupal_image() where possible by drupal_field() Fixed (but that was a more simple case!)

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

4.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024