Notice: Trying to access array offset on value of type null in image_field_views_data_views_data_alter() line 44, line 56, 57

Issue fork views-3211785

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alin_cut created an issue. See original summary.

alin_cut’s picture

DamienMcKenna’s picture

Status: Needs review » Needs work

Sorry, but that's not how you should handle it, isset() returns a boolean whereas those variables expect a string.

Could you please explain what triggered the problem? What version of PHP are you using? What sort of data are you viewing? Could you please export the view and paste it here so we can review it? Thank you.

VladimirAus’s picture

Clearing cache from Performance page on PHP 7.4.15.

After applying patch from #3153312: PHP 7.4 warnings with disabled Comment module the following errors still exist

Notice: Trying to access array offset on value of type null in image_field_views_data_views_data_alter() (line 44 of /docroot/sites/all/modules/views/modules/image.views.inc).
Notice: Trying to access array offset on value of type null in image_field_views_data_views_data_alter() (line 56 of /docroot/sites/all/modules/views/modules/image.views.inc).
Notice: Trying to access array offset on value of type null in image_field_views_data_views_data_alter() (line 57 of /docroot/sites/all/modules/views/modules/image.views.inc).
Notice: Trying to access array offset on value of type null in image_field_views_data_views_data_alter() (line 57 of /docroot/sites/all/modules/views/modules/image.views.inc).
tonysbag’s picture

Same errors when we upgrade php to version 7.4 from 7.3. I got these errors after i cleared cache.
I think "Trying to access array offset on value of type null" is the only problem we need to solve it.
I dont know much about coding but maybe we should do some coding like check if the value is set.
Thank you!

kevster’s picture

Im seeing this too on latest views but its field not image - Drupal 7.81, PHP 7.4.20

Notice: Trying to access array offset on value of type null in field_views_field_default_views_data() (line 123 of .../sites/all/modules/views/modules/field.views.inc).

percoction’s picture

DamienMcKenna’s picture

Issue tags: +Needs tests

These changes are incorrect and will break things, e.g.:

-    $entity = $entity_info['label'];
+    $entity = isset($entity_info['label']);

That's supposed to store a string but you're changing it to a boolean. All of the changes made are like that, i.e. they're all incorrect.

The bigger issue is why $entity_info is empty in the first place.

jenlampton’s picture

Status: Needs work » Needs review
FileSize
2.92 KB

Here's a safer patch that checks for $entity_info before using it to build the $data array.

> The bigger issue is why $entity_info is empty in the first place.

This site is using the profile2 module and the profile has an image field. Here, 'profile2' appears in $bundles as an entity type (its bundle is listed as 'main'), but that doesn't have any entity info.

I agree that this is more likely an issue with Profile2, but I'll just fix up this patch on my way over there...

This article might also be useful for some who land here:
Data fix: Field [field] refers to nonexistent entity type [type].
(check your logs to see if you have this error)

VladimirAus’s picture

Version: 7.x-3.24 » 7.x-3.25
Status: Needs review » Reviewed & tested by the community

That worked on PHP 7.4 both locally and on Acquia.
Thanks.

DamienMcKenna’s picture

Title: Trying to access array offset on value of type null in image_field_views_data_views_data_alter() » Trying to access array offset on value of type null in image_field_views_data_views_data_alter()
Version: 7.x-3.25 » 7.x-3.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests
Parent issue: » #3232189: Plan for Views 7.x-3.26

Seems like a minor thing, it probably is a bug in another module, but I don't see any harm in the change. Thanks JenLampton.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.