Fatal error when adding a field to any entity type (e.g., basic page node) with GDPR module enabled on Drupal 10.2.1

Created on 12 January 2024, 11 months ago
Updated 31 July 2024, 4 months ago

I encountered a fatal error when trying to add a new plaintext field to an entity type using the Drupal GDPR module. The issue appears when I add the plaintext field to a basic page node as an example, but it seems to occur with any entity type.

Steps to reproduce:

  • Navigate to the 'Manage fields' configuration page of any entity type (e.g., basic page node) with the GDPR module enabled.
  • Try adding a new plaintext field to the content type.
  • Save the field settings.
  • Actual result: After saving the field settings, the following error is displayed:

The website encountered an unexpected error. Please try again later.

Error: Call to a member function getType() on null in Drupal\gdpr_fields\Form\GdprFieldSettingsForm::buildFormFields() (line 281 of modules/contrib/gdpr/modules/gdpr_fields/src/Form/GdprFieldSettingsForm.php).
Expected result: The new plaintext field should be added to the entity type without any errors.

Environment:
Drupal version: 10.2.1
PHP version: 8.3.0
GDPR module version: 3.0.0

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇳🇱Netherlands rbosscher

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

Merge Requests

Comments & Activities

  • Issue created by @rbosscher
  • Status changed to Needs review 11 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    1 pass
  • 🇮🇳India keshavv India

    Created patch. Please test.

  • 🇳🇱Netherlands rbosscher

    Hi thanks for the patch, it seems to fix it at line 281, but now raises a new error:

    TypeError: Drupal\gdpr_fields\Entity\GdprField::propertyCanBeRemoved(): Argument #1 ($field_definition) must be of type Drupal\Core\Field\FieldDefinitionInterface, null given, called in /var/www/public_html/modules/contrib/gdpr/modules/gdpr_fields/src/Form/GdprFieldSettingsForm.php on line 378 in Drupal\gdpr_fields\Entity\GdprField->propertyCanBeRemoved() (line 369 of modules/contrib/gdpr/modules/gdpr_fields/src/Entity/GdprField.php).

  • 🇳🇱Netherlands rbosscher

    It appears that:

    `$fieldDefinition = $fieldManager->getFieldDefinitions($entity_type, $bundle_name)[$field_name]` returns `null`.

    On the other hand, `$fieldDefinition = $fieldManager->getFieldDefinitions($entity_type, $bundle_name)` returns the current entity without the field that is yet to be created. So it returns null because the new field is not in the fieldDefinition.

    Not sure this is a breaking change in core as the fieldmanger is identical to 10.1

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    1 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 7.4 & MySQL 5.7
    last update 10 months ago
    Composer require failure
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    1 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    1 pass
  • Any update on this issue ?

    In my D10.2 application , For the patch #2 it is still raising this error

    TypeError: Drupal\gdpr_fields\Entity\GdprField::propertyCanBeRemoved(): Argument #1 ($field_definition) must be of type Drupal\Core\Field\FieldDefinitionInterface, null

    Using the #5 seems to bypass the error and let user create fields but it still throws this warning when I am trying.

    Warning: Undefined array key "field_x" in Drupal\gdpr_fields\Form\GdprFieldSettingsForm::buildFormFields()

    This is quite a major issue hope it can be resolved quickly.

  • 🇧🇪Belgium bart lambert

    I'm having the same issue.
    Applied patch issue_3414301.patch but i'm now getting following error:

    Warning: Undefined array key "field_url_van_de_video" in Drupal\gdpr_fields\Form\GdprFieldSettingsForm::buildFormFields() (line 263 of modules/contrib/gdpr/modules/gdpr_fields/src/Form/GdprFieldSettingsForm.php).

    So I think somewhere there is still something missing....

    Any Idea's how To fix this?

  • First commit to issue fork.
  • 🇭🇺Hungary eFeS

    I've the same situation as EZKG. Neither patch #2, nor #5 solved the initial problem under Drupal 10.2.5, PHP8.1.27

  • 🇳🇱Netherlands ahmetburkan Utrecht

    After some detective work and debugging i think that we need to think about how we approach this issue. See 3383986

    Current situation:
    There is a workaround patch at comment #5 🐛 Fatal error when adding a field to any entity type (e.g., basic page node) with GDPR module enabled on Drupal 10.2.1 Needs review . This will disable the functionality to be able to configure GDPR fields while creating the new field. After saving the field editing the GDPR settings is possible. This requires an extra step for now.

    Future:
    We need to make a discission how we continue because it is not possible anymore to load the newly created field because it hasn't been saved until the last step in the field creation flow. That makes the function getFieldDefinitions() obsolete when calling it from the 'gdpr_fields.module' but not when you go directly to the route after saving the new field.

  • Status changed to Needs work 7 months ago
  • 🇳🇱Netherlands ahmetburkan Utrecht

    Update status.

  • 🇳🇱Netherlands eelkeblok Netherlands 🇳🇱

    I think the information that is being pulled from the field config should also be available in the form state for the form when first creating the field. We should probably make a change such that the code can get the required information from there too, if it needs to. Both for the standalone GDPR config form as well as the previous core version.

  • 🇳🇱Netherlands ahmetburkan Utrecht

    ahmetburkan changed the visibility of the branch 3414301-fatal-error-when to hidden.

  • 🇳🇱Netherlands ahmetburkan Utrecht

    ahmetburkan changed the visibility of the branch 3414301-fatal-error-when to hidden.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 7 months ago
    1 pass
  • Status changed to Needs review 7 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 7 months ago
    1 pass
  • 🇳🇱Netherlands ahmetburkan Utrecht
  • Status changed to Needs work 7 months ago
  • 🇳🇱Netherlands eelkeblok Netherlands 🇳🇱
  • 🇳🇱Netherlands eelkeblok Netherlands 🇳🇱

    As a generic comment, in addition to the detailed comments in the MR, I wonder whether the buildFormFields() method could be simplified; the buildForm, which is the other place that calls this, I already checking if the field config exists, so it would be a small change to have it pass that into the buildFormFields(). If we can move the burden of getting the proper field config to the calling code (either pulling it from field storage, or from the form state when in the field creation flow), that could simplify the buildFormFields method a great deal.

    Maybe this should become a follow-up, since the module is actually actively braking Drupal 10.2 sites.

    Must-fix changes:

  • 🇭🇺Hungary eFeS

    Is there any progress with this?

  • 🇮🇳India rajeshreeputra Pune

    changes seems working, agree with @eelkeblok that this change might break with lower drupal version. To avoid this we should add test to create content type and add field to it.

  • First commit to issue fork.
  • Pipeline finished with Failed
    4 months ago
    Total: 151s
    #224694
  • Pipeline finished with Success
    4 months ago
    Total: 159s
    #224706
  • Pipeline finished with Success
    4 months ago
    #224710
  • Status changed to Needs review 4 months ago
  • Status changed to RTBC 4 months ago
  • 🇮🇳India deepakkm

    Verified changes locally its working fine.

  • Pipeline finished with Skipped
    4 months ago
    #226391
  • Status changed to Fixed 4 months ago
  • 🇮🇳India rajeshreeputra Pune

    Merged release to follow shortly.

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

Production build 0.71.5 2024