Prevent modules from being uninstalled if they provide field types used in an Experience Builder field

Created on 30 May 2024, about 1 year ago
Updated 21 June 2024, 12 months ago

Problem/Motivation

If a field used in a experience builder field there is nothing stopping the module that provides that field from being uninstalled

Steps to reproduce

  1. Use a field in experience builder field
  2. uninstall the module that provide the field
  3. view the entity that used the field
  4. Should get a 'Unhandled expression type.' exception

Proposed resolution

we'll need to implement something like `\Drupal\field\FieldUninstallValidator` instead. And thanks to the expressions, we easily can:

  1. new `\Drupal\experience_builder\FieldUninstallValidator` service
  2. assume the module being uninstalled provides field type `foobar`
  3. iterates over all XB field instances, for each field instance:
  4. determine the DB table of the _current_ data (e.g. `node__field_xb_demo`) as well as the _revision_ data (e.g. `node_revision__field_xb_demo`)
  5. determine the prop expression prefix that should not occur for this module to be safely uninstallable: `new FieldTypePropExpression('foobar', '')` (yes, use the empty string as the field prop name β€” not semantically beautiful, but pragmatic at this stage)
  6. determine which entities use an instance of the `foobar` field type inside`XB`: `SELECT entity_id, JSON_SEARCH(field_xb_demo_props, 'all', '`:information_source:`foobar␟%') FROM node__field_xb_demo`
  7. For all XB field instances we will also need to check the default values to ensure the field type `foobar` is not used there either

The result is _one query per entity type_ to find where XB uses instances of this field type to assign static props values.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Fixed

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024