TypeError: entity_views_field_definition(): Argument #2 ($property_info) must be of type array, null given

Created on 28 November 2022, about 2 years ago
Updated 30 March 2023, almost 2 years ago

Problem/Motivation

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code - misc

Created by

πŸ‡ΊπŸ‡¦Ukraine voleger Ukraine, Rivne

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ͺπŸ‡ͺEstonia tormi Tallinn

    RTBC.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡¨πŸ‡¦Canada nedjo

    Thanks for reporting the issue and contributing a proposed fix.

    I haven't seen this issue occur, just commenting as part of going through reported PHP 8.1 compatibility issues. I've only taken a brief glance so my comment should be taken as tentative notes made while passing through.

    That said...

    The issue appears to be in the data returned by entity_get_all_property_info(). The relevant code in entity_views_field_definition() looks to expect a keyed array for the array $property_info argument. So casting as an array whatever data is returned by entity_get_all_property_info() may mask the error without addressing the root cause.

    Suggested next step in debugging: determine what non-array values are being returned as part of the entity_get_all_property_info() return value and debug from there, considering the possibilities that the issue may or may not be in this module.

    Hope that's helpful!

  • πŸ‡¨πŸ‡¦Canada nedjo
    -  $title = $title_prefix . $property_info['label'];
    +  $title = $title_prefix . (isset($property_info['label']) ? $property_info['label'] : '');
    

    Re this bit, hmm. It looks like it's possible to get back a $property_info array that doesn't have a 'label' key. Is that a valid result? If so, then, yes, this appears to be an appropriate use for the ternary operator.

    Since this snippet appears to be constructing a user-facing string, it's not totally clear that the $title_prefix is expected to be valid on its own. This call in entity_views_field_definition() feeds a string that would look odd on its own:

    entity_views_field_definition($field . ':' . $nested_key, $nested_property, $table, $title . ' Β» ');
    

    In that usage, in the case of a missing 'label' key, we might want just the $title without the ' Β» '. Though whether that's an edge case that's worth addressing at this point....

Production build 0.71.5 2024