Problem/Motivation

Opening this as an issue to track and solve an issue that @symioquine discovered: bundle fields defined via hook_farm_entity_bundle_field_info() cannot be written to via JSON:API.

@symbioquine tracked this to a Drupal core issue related to the core hook_entity_bundle_field_info() hook: #3045509: EntityFieldManager key/value field map gets out of sync, doesn't recognise bundle fields

I (@mstenta) confirmed that this issue affects farmOS's hook as well (because it uses that core hook behind the scenes via the Entity API module). See my comment here for more info: https://www.drupal.org/project/drupal/issues/3045509#comment-14726416

Steps to reproduce

  1. Create a custom module that adds a bundle field to an existing asset/log type via hook_farm_entity_bundle_field_info() (see: https://farmos.org/development/module/fields/#bundle-fields)
  2. Attempt to write to this new field via JSON:API, and observe that it does not work.

Proposed resolution

The upstream issue is tricky to solve in core (see the core issue for details why). So, I propose we solve this in farmOS as a first step, and if Drupal core solves it we can adopt that in the future.

We can solve this by implementing hook_modules_installed() and hook_modules_uninstalled() to update field maps when modules that implement hook_farm_entity_bundle_field_info() are installed/uninstalled.

We will also need an update hook to fix bundle fields in modules that have already been installed on existing deployments.

Remaining tasks

  • Implement hook_modules_installed() to add farmOS bundle fields to the field map.
  • Implement hook_modules_uninstalled() to remove farmOS bundle fields from the field map.
  • Implement hook_post_update_NAME() to add farmOS bundle fields to the field map on existing deployments.
  • Automated tests.

User interface changes

None.

API changes

Fix the ability to write to farmOS bundle fields via the API.

Data model changes

None.

Comments

m.stenta created an issue. See original summary.

m.stenta’s picture

Issue tags: +stable blocker
m.stenta’s picture

m.stenta’s picture

Status: Active » Needs review

Opened a pull request to fix this: https://github.com/farmOS/farmOS/pull/583

m.stenta’s picture

Status: Needs review » Needs work
m.stenta’s picture

Issue tags: -stable blocker
m.stenta’s picture

Version: 2.x-dev » 3.x-dev
m.stenta’s picture

Status: Needs work » Needs review
Related issues: +#3129179: Provide some way to rebuild the persistent bundle field map

  • m.stenta committed 1bcc2942 on 3.x
    Issue #3314741: EntityFieldManager::getFieldMap() doesn't show farmOS...

  • m.stenta committed 3f2734cb on 3.x
    Issue #3314741: EntityFieldManager::getFieldMap() doesn't show farmOS...
paul121’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

m.stenta’s picture

Update: Drupal core has fixed the root cause of this in #3045509: EntityFieldManager key/value field map gets out of sync, doesn't recognise bundle fields

This hasn't been merged yet.

I've opened a draft PR to prepare for undoing our fix: https://github.com/farmOS/farmOS/pull/1074