JSON:API Extras field config sticks when field is removed

Created on 8 February 2019, over 6 years ago
Updated 31 August 2023, almost 2 years ago

If you have configured an endpoint for a content type and remove a field, it will still be on the form in JSONAPI config. I had to manually edit the config file to fully remove.

๐Ÿ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States mortona2k Seattle

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

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.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands bbrala Netherlands
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands bbrala Netherlands
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jrockowitz Brooklyn, NY

    I was experimenting with this patch and a bunch of update hooks failed with the below error

    LogicException: withRelatableResourceTypes() must be called before getting relatable resource types. in Drupal\jsonapi\ResourceType\ResourceTypeRelationship->getRelatableResourceTypes() (line 48 of /var/www/html/docroot/core/modules/jsonapi/src/ResourceType/ResourceTypeRelationship.php) #0 /var/www/html/docroot/core/modules/jsonapi/src/ResourceType/ResourceType.php(406): Drupal\jsonapi\ResourceType\ResourceTypeRelationship->getRelatableResourceTypes()

    Sorry, I can't provide more details.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia virag.jain

    Update on the issue:

    An initial attempt was made to fix this by implementing \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig::onDependencyRemoval(), as pointed out by @Wim Leers, with the goal of cleaning up deleted fields from the resourceFields array. However, it turned out that the method onDependencyRemoval() wasnโ€™t being triggered at all when a field was removed.

    Upon further investigation, it appears the root cause is that \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig::calculateDependencies() only adds the only adds the bundle (e.g. node.type.*) as a dependency; it doesnโ€™t include individual field configs like field.storage.node.field_foo. Without those dependencies, the entity system doesnโ€™t invoke onDependencyRemoval() when fields are deleted.

    Proposed solution:

    The plan is to update calculateDependencies() to explicitly add each field listed in resourceFields as a dependency (e.g., field.storage.node.field_foo). With that in place, onDependencyRemoval() will be properly triggered when a field is deleted.

    Inside onDependencyRemoval(), any removed fields will be automatically cleaned out of the override config. This prevents stale field entries from lingering in the YAML and eliminates the need for manual cleanup.

    Just wanted to check in and see if this approach makes sense before finalising the patch. Let me know your thoughts!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia virag.jain
Production build 0.71.5 2024