EntityFieldManager::getFieldMap() doesn't show farmOS bundle fields

Created on 11 October 2022, over 2 years ago
Updated 12 September 2024, 4 months ago

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::getFieldMap() doesn't show 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.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States m.stenta

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024