Fatal error in 3.1.8

Created on 24 May 2025, about 1 month ago

Problem/Motivation

After upgrading to 3.1.8, when accessing a field, I get the fatal error:

Error: Typed property Drupal\custom_field\Plugin\Field\FieldWidget\CustomWidgetBase::$customFieldTypeManager must not be accessed before initialization in Drupal\custom_field\Plugin\Field\FieldWidget\CustomWidgetBase->getCustomFieldItems() (line 160 of modules/contrib/custom_field/src/Plugin/Field/FieldWidget/CustomWidgetBase.php).

If I revert to 3.1.7, the problem goes away, so it's something introduced in 3.1.8.

πŸ› Bug report
Status

Active

Version

3.1

Component

User interface

Created by

πŸ‡¨πŸ‡¦Canada jaypan Victoria, BC

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

Comments & Activities

  • Issue created by @jaypan
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Is there anything else u can provide to help me reproduce? Drupal version, anything particular about the setup with the form? Layout builder or paragraphs in the mix?

  • πŸ‡¨πŸ‡¦Canada jaypan Victoria, BC

    I figured out the problem. I was extending CustomFlexWidget to create a custom widget, and I had extended the create() function. I was setting $instance->customFieldManager in 3.1.7, I needed to change this to $instance->customFieldTypeManager in 3.1.8, as it appears the property name changed between versions.

  • πŸ‡¨πŸ‡¦Canada jaypan Victoria, BC

    A way to prevent this type of issue in the future, would be to remove the call to create() altogether, and then add functions to retrieve the managers that initialize them before returning them. So you can add these getters:

    <?php
    public function getCustomFieldTypeManager() {
    if (!isset($this->customFieldTypeManager)) {
    $this->customFieldTypeManager = \Drupal::service('plugin.manager.custom_field_type');
    }

    return $this->customFieldTypeManager;
    }

    public function getCustomFieldWidgetManager() {
    if (!isset($this->customFieldWidgetManager)) {
    $this->customFieldWidgetManager = \Drupal::service('plugin.manager.custom_field_widget');
    }

    return $this->customFieldWidgetManager;
    }

    Then change instances of $this->customFieldTypeManager to $this->getCustomFieldTypeManager() and $this->customFieldWidgetManager to $this->getCustomFieldWidgetManager(). This way, if you change the property names in the future, classes that extend your class will not be affected.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner
Production build 0.71.5 2024