Error: Class "Drupal\bg_img_field\Plugin\Field\FieldFormatter\File" not found in Drupal\bg_img_field\Plugin\Field\FieldFormatter\BgImgFieldFormatter->viewElements()

Created on 5 June 2024, 25 days ago
Updated 27 June 2024, 4 days ago

Problem/Motivation

Error: Class "Drupal\bg_img_field\Plugin\Field\FieldFormatter\File" not found in Drupal\bg_img_field\Plugin\Field\FieldFormatter\BgImgFieldFormatter->viewElements() on line 188

/modules/contrib/bg_img_field/src/Plugin/Field/FieldFormatter/BgImgFieldFormatter.php).

Steps to reproduce

I upgraded this module from version 1.7 that i had patched to use in Drupal 10, but the new code comes with a break in the code and unexpected error pages

Proposed resolution

I changed line 189 like it was before in version 1.7 'file' => File::load($item['target_id']),

and
use Drupal\file\Entity\File; was included back again like it was in version 1.7 and everything worked

See screenshots attached

🐛 Bug report
Status

Needs review

Version

2.1

Component

Code

Created by

🇺🇬Uganda Thomas Kaisuka

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

Comments & Activities

  • Issue created by @Thomas Kaisuka
  • Status changed to Needs review 4 days ago
  • 🇮🇳India sarwan

    Hi @Thomas Kaisuka,

    I have resolved this issue "Error: Class "Drupal\bg_img_field\Plugin\Field\FieldFormatter\File" not found in Drupal\bg_img_field\Plugin\Field\FieldFormatter\BgImgFieldFormatter->viewElements()" and also attached the patch,
    please review and verify.

  • 🇮🇳India Sandeep_k New Delhi

    Hi @sarwan_verma, I've tested shared Patch- bg_img_field-3452677 on Drupal version- 10.3-dev. The patch was applied successfully but the error is still does not fixed for me, Added before and after patch results.

Production build 0.69.0 2024