Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294610

Formatter 'URL to image' from ImageUrlFormatter shows PHP warning due to the newly introduced loading attribute on image field

$
0
0

Problem/Motivation

PHP displays warning when choosing image formatter "URL to image" on 9.4 fresh installation.

The new attribute 'loading' was introduced with $image_loading = $this->getSetting('image_loading'); on Drupal 9.4 #3173180: Add UI for 'loading' html attribute to images in web/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php

Yet the Class extending it web/core/modules/image/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php does not make use of it while making its parent calls, and doesn't provide the missing setting in its defaultSettings() function. Therefore returning NULL on the getSetting function, which gives the warning below on building settingsForm and settingsSummary.

Warning: Trying to access array offset on value of type null in Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter->settingsForm() (line 167 of /app/web/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php)
#0 /app/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(2, 'Trying to acces...', '/app/web/core/m...', 167)
#1 /app/web/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php(167): _drupal_error_handler(2, 'Trying to acces...', '/app/web/core/m...', 167)
#2 /app/web/core/modules/image/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php(35): Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter->settingsForm(Array, Object(Drupal\Core\Form\FormState))
#3 /app/web/core/modules/field_ui/src/Form/EntityDisplayFormBase.php(446): Drupal\image\Plugin\Field\FieldFormatter\ImageUrlFormatter->settingsForm(Array, Object(Drupal\Core\Form\FormState))
#4 /app/web/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php(40): Drupal\field_ui\Form\EntityDisplayFormBase->buildFieldRow(Object(Drupal\field\Entity\FieldConfig), Array, Object(Drupal\Core\Form\FormState))
#5 /app/web/core/modules/field_ui/src/Form/EntityDisplayFormBase.php(209): Drupal\field_ui\Form\EntityViewDisplayEditForm->buildFieldRow(Object(Drupal\field\Entity\FieldConfig), Array, Object(Drupal\Core\Form\FormState))
#6 /app/web/core/lib/Drupal/Core/Entity/EntityForm.php(106): Drupal\field_ui\Form\EntityDisplayFormBase->form(Array, Object(Drupal\Core\Form\FormState))

Steps to reproduce

  1. Install Latest 9.4.x dev site
  2. Modify article's image display settings /admin/structure/types/manage/article/display
  3. Change Image format from 'Image' to 'URL to image'
  4. Head to /admin/reports/dblog to see the php warning report

Proposed resolution

1. Skip the generation of loading related array if setting retrieved is NULL.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 294610

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>