$colorboxAttachment must not be accessed before initialization

Created on 14 February 2024, 11 months ago
Updated 28 February 2024, 10 months ago

Problem/Motivation

After installation, and after setting a field formatter to use Colorbox FF, default options, I'm getting this error when viewing the node that should have a reference field using this formatter:

AH01071: Got error 'PHP message: Uncaught PHP Exception Error: "Typed property Drupal\\colorbox_field_formatter\\Plugin\\Field\\FieldFormatter\\ColorboxFieldFormatter::$colorboxAttachment must not be accessed before initialization" at /var/www/clients/client1/web1/web/repo/igf/web/modules/contrib/colorbox_field_formatter/src/Plugin/Field/FieldFormatter/ColorboxFieldFormatter.php line 300'

Steps to reproduce

Install this module on the 2.1.1 version, using Drupal 10.1, PHP 8.2, colorbox 2.0.1, colorbox_load 1.3

Proposed resolution

I have tried to add this:
protected ColorboxAttachment $colorboxAttachment = NULL;

but whithout success.

🐛 Bug report
Status

Fixed

Version

2.1

Component

Code

Created by

🇵🇹Portugal jrochate

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

Comments & Activities

  • Issue created by @jrochate
    • jurgenhaas committed b903a9ea on 2.1.x
      Issue #3421355: $colorboxAttachment must not be accessed before...
  • Status changed to Needs review 11 months ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks for reporting this @jrochate. I've fixed it in the dev release, please review. Not sure how we could have missed that in the first place, that variable never got initialized in the previous code.

  • 🇮🇳India Raveen Kumar

    @jrochate,
    The error message you're encountering indicates that you're trying to access a typed property $colorboxAttachment in the ColorboxFieldFormatter class before it has been initialized. This could be due to accessing the property directly without assigning a value to it first.

    ** To resolve this issue, you need to ensure that the $colorboxAttachment property is properly initialized before accessing it. This could involve assigning a value to it in the constructor or in a method that is called before you try to access it.

  • 🇵🇹Portugal jrochate

    Thanks 🐛 $colorboxAttachment must not be accessed before initialization Needs review , that quickly solved the PHP error I was getting.

    On this use-case I have an entity reference field that links to another entity. When I setup the formatter "Colorbox FF", I get this default options:

    Style: Default
    Link to Content
    Width: 500
    Height: 500
    iFrame Mode: Yes
    

    I think that's ok, but when I go to node display, the entity reference field gets the title NOT FROM the referenced node, but from the viewed node itself!

    Something like:
    Node A has Field X, entity referenced to Node X

    - Without Colorbox FF, when I view Node A, I see a link to Node X on Field X
    - When press on the link, I get a new page with Node X opens

    - WIth Colorbox FF, when I view Node A, I seed a link to node A on Field X
    - When press on the link, I get a black screen with a small X on the corner

    Is this the normal module behaviour or is a colateral damage from the fix?

    TIA

  • 🇩🇪Germany jurgenhaas Gottmadingen

    So, the original problem is solved then. The second problem should be a separate issue. It can't be a consequence of the fix because without the fix that module didn't work under any circumstance.

    Let's RTBC and fix this one, then we can address the other topic on its own in another issue. But that would require someone to build and debug the code to find out where this is going wrong. I probably won't be able to do that soon'ish as I don't have any site where we're using that module any longer.

  • Status changed to RTBC 11 months ago
  • Status changed to Fixed 11 months ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks. I've just checked, this bug did not exist in earlier versions, it got introduced in the 2.1.x branch only. Marking now as fixed.

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

Production build 0.71.5 2024