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
Comments
Comment #2
sarwan_verma commentedHi @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.
Comment #3
sandeep_k commentedHi @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.
Comment #4
nicholass10.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.Comment #5
nicholassPlus 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.
Comment #6
nicholassI started a new issue but check out https://www.drupal.org/project/bg_img_field/issues/3484950 and see if it solves your orginal error, I never got your exact error, but I assume it stems from the same bad code.
Comment #7
john franklin commentedClosing as a duplicate of #3484950: Error: Call to a member function load() on null BgImgFieldFormatter.