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, 6 months 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

Active

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 5 months ago
  • 🇮🇳India sarwan_verma

    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.

  • 🇺🇸United States NicholasS

    10.3 I get Error: Call to a member function load() on null in Drupal\bg_img_field\Plugin\Field\FieldFormatter\BgImgFieldFormatter->viewElements() (line 188 of modules/contrib/bg_img_field/src/Plugin/Field/FieldFormatter/BgImgFieldFormatter.php). which is the same line this issue has a problem with.

  • 🇺🇸United States NicholasS

    Plus I get

    Warning: Undefined variable $fileSystem in Drupal\bg_img_field\Plugin\Field\FieldFormatter\BgImgFieldFormatter->__construct() (line 117 of modules/contrib/bg_img_field/src/Plugin/Field/FieldFormatter/BgImgFieldFormatter.php).

    and

    Warning: Undefined variable $imageFactory in Drupal\bg_img_field\Plugin\Field\FieldFormatter\BgImgFieldFormatter->__construct() (line 118 of modules/contrib/bg_img_field/src/Plugin/Field/FieldFormatter/BgImgFieldFormatter.php).

    So not sure how 2.1 release is working for anyone! But the undefined vars probably explains your original issue.

  • 🇺🇸United States NicholasS

    I started a new issue but check out https://www.drupal.org/project/bg_img_field/issues/3484950 🐛 Error: Call to a member function load() on null BgImgFieldFormatter Active and see if it solves your orginal error, I never got your exact error, but I assume it stems from the same bad code.

Production build 0.71.5 2024