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
- Install Latest 9.4.x dev site
- Modify article's image display settings /admin/structure/types/manage/article/display
- Change Image format from 'Image' to 'URL to image'
- 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.