Make the module Drupal 10.2.x compatible (Cannot create new fields)

Created on 22 December 2023, 11 months ago
Updated 5 February 2024, 9 months ago

Problem/Motivation

When this module is enabled, I am unable to create new fields. While creating a new field, when I click to "Save settings" on the field storage config settings page, I instead see a white screen of death, telling me that the field already exists. I have made sure that the field does not exist, and even tried creating fields with names that I would not ever use to make sure.

Steps to reproduce

  1. Enable the module
  2. Start creating a new field on some content type
  3. When I first get to the field storage settings page, the "Save settings" button is blue and clickable. Clicking it at this point does result in a fatal error.
  4. Now I am not sure if this is related to the problem I am reporting (maybe), but if instead of saving right away I change the field to a multi-value field, the "Save settings" button becomes greyed out and unclickable. I found I could get it clickable again by putting anything into the default value field. I can then keep or delete what is there, and either way the button will remain clickable, and still result in a fatal error.
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

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

Merge Requests

Comments & Activities

  • Issue created by @MegaKeegMan
  • Status changed to Postponed: needs info 11 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Thanks for your report @MegaKeegMan. I can't yet imagine, how this module should cause that issue.

    Could you please write down steps to reproduce this in a fresh Drupal environment? My bet is, that this module is not causing the issue, but it's due to other, individual reasons. But I'm happy to help, if we can reproduce this in vanilla.

  • πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

    You are right. I am unable to reproduce this on a fresh Drupal instance. I do not understand either why I am hitting this error on the site for which I am looking to use this module. All I know is that it does not occur when this module is not enabled. I will report back if I learn anything. Thanks getting back to me!

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Thanks @MegaKeegMan! Sorry I also don't have an idea, but I think you should link for orphaned entries of your "field_another_test" field in your config and remove them. Looks like the field was created partially.

    Does the error occur for any random field name you choose?

  • πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

    Yes, it occurs no matter which field name I choose. I checked my config and found no traces of any of the fields. I don't believe the error to be accurate. I will investigate it again, but I have some other priorities at the moment.

  • Assigned to Grevil
  • Status changed to Active 10 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Hooray, I was now able to reproduce the issue with a Media reference field in Drupal 10.2.1!
    In the first step, when I select a media type, the AJAX spinner loads and afterwards the submit button has disabled and in the log I can see the error:

    Drupal\Core\Entity\EntityStorageException: 'field_storage_config' entity with ID 'commerce_product_variation.field_coverimage' already exists. in Drupal\Core\Entity\EntityStorageBase->doPreSave() (Zeile 519 in /web/core/lib/Drupal/Core/Entity/EntityStorageBase.php).

    The backtrace then lists this module's hook:

    #4 web/modules/contrib/entity_access_by_reference_field/entity_access_by_reference_field.module(201): Drupal\Core\Config\Entity\ConfigEntityBase->save()
    #5 [internal function]: entity_access_by_reference_field_field_config_edit_form_builder()
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @MegaKeegMan did you find any fix in the meantime which you could provide as MR for a starting point?

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    The technical reason is the ->save() call here:

    function entity_access_by_reference_field_field_config_edit_form_builder($entity_type, FieldStorageConfig $storage, array &$form, FormStateInterface $form_state) {
      $storage->setThirdPartySetting('entity_access_by_reference_field', 'enable_referenced_entity_permission', $form_state->getValue('enable_referenced_entity_permission'));
      $storage->setThirdPartySetting('entity_access_by_reference_field', 'permission_matrix', $form_state->getValue('permission_matrix'));
      $storage->setThirdPartySetting('entity_access_by_reference_field', 'access_fallback', $form_state->getValue('access_fallback'));
      $storage->setThirdPartySetting('entity_access_by_reference_field', 'access_fallback_empty', $form_state->getValue('access_fallback_empty'));
      $storage->setThirdPartySetting('entity_access_by_reference_field', 'multiple_entities_behavior', $form_state->getValue('multiple_entities_behavior'));
      $storage->save();
    }
    

    We should try if it works without the explicit ->save() that would be the most simple solution.

    Otherwise, we would need to find out, when this may be saved and when not. In this case it's definitely to early and triggered by the AJAX call!

  • πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

    No, but if I had a fix I would absolutely contribute it. I have actually switched to using the access policy module for my current project. I was a bit hesitant to use it at first because it is pretty complex, but I am happy to be learning it now. I am glad that you were able to reproduce the issue, though. It is a pretty strange one.

  • First commit to issue fork.
  • πŸ‡©πŸ‡ͺGermany Grevil

    I can replicate this issue with ANY referenced type. Whether it is a content reference field, taxonomy field or media reference field!!!

    Quite disturbing actually... this module is quite well tested, but we always create the fields programmatically for the setup.... definitely adding some UI field setup tests!

  • πŸ‡©πŸ‡ͺGermany Grevil

    Ok, I found a similiar issue in field_permissions. Seems, that this is a D 10.2 only issue, see πŸ› D10.2, Add Select field Error Fixed .

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Nice!!! The fix seems fine, but please add a comment leading to this issue :D

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    18 pass
  • πŸ‡©πŸ‡ͺGermany Grevil

    Again, thanks @MegaKeegMan! Since 10.2 quite a bit changed for the field storage settings and field settings page! They both got merged into one, even though they tried to preserve the functionality for the field_config and field_storage_config hooks for normal configs, the field_storage_config hook seems to be broken for third party settings.

    But we can now delete our old field_config hook and just put the storage hook code into the field_config hook implementation! Saving us a few lines of code and a working module with Drupal 10.2!

    Please review!

  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
    • Grevil β†’ committed 062e584d on 1.x
      Related to Issue #3410606: Remove compatibility with Drupal 10.2 and...
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    18 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    18 pass
  • πŸ‡©πŸ‡ͺGermany Grevil

    Concerning #11, it is currently not possible to create non JS tests, testing the creation of a field via UI.... The new UI simply doesn't work without JavaScript (At least not for reference fields)! πŸ˜…

    And with JS it is a pain in the ass, since the ids are not very good and the "checkboxes" are not actual checkboxes but inputs with a preset value, so "checking" the input field with a value like "true" doesn't actually do anything. No idea how to test it if the test page mehtods like "$page->fillField()" or $page->checkField()" do not apply to these....

    But yea we found the main issue, let's see if we can create some tests in the future, when they add non js support.

  • πŸ‡©πŸ‡ͺGermany Grevil
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Reviewed just the code and LGTM!

    We please need more feedback if it works and fixes the issues for anyone using 10.2 with this MR!

  • πŸ‡©πŸ‡ͺGermany Grevil
  • Status changed to RTBC 10 months ago
    • Grevil β†’ committed dc986e1f on 1.x
      Issue #3410606 by Grevil, MegaKeegMan, Anybody: Make the module Drupal...
  • Status changed to Fixed 10 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Thanks :)

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

Production build 0.71.5 2024