field.storage YAML and FieldType plugin cannot coexist in same module because of FieldUninstallValidator constraint

Created on 20 April 2017, over 7 years ago
Updated 3 June 2024, 7 months ago

Problem/Motivation

When a module defines a custom FieldType plugin (for example, custom_field_type) and this FieldType storage is implemented in a field.storage YAML file (for example in field.storage.commerce_product.custom_field.yml), the module cannot be uninstalled anymore because the error The %field_type_label field type is used in the following field: @fields is triggered by Drupal\field\FieldUninstallValidator.

This is logical behavior because normally the FieldType plugin should not be removed as long as implementations exist. However, in some scenarios removal of the plugin should also trigger removal of dependent implementations. This would be the case for example when the FieldType storage implementation YAML exists in the same module as the FieldType plugin.

Proposed resolution

Do not abort the uninstall procedure in Drupal\field\FieldUninstallValidator if the module that is being removed contains the FieldType plugin when it is defined as an enforced module dependency in the FieldType storage implementation that would otherwise trigger the abortion.

Remaining tasks

Does the patch still apply?
Review
Commit

API changes

Any field storage definition that needs to be deleted should include the module name (example_module) that defines the FieldType plugin an enforced module dependency with the following YAML code:

dependencies:
  module:
    - example_module
  enforced:
      module:
        - example_module
πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

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.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

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

    @rivimey #46 following up on this as it relates to commerce_recurring.

    Has anyone used the patch in #41 successfully in this use case?

  • πŸ‡ΊπŸ‡ΈUnited States pmagunia Philadelphia πŸ‡ΊπŸ‡Έ

    Even after the patch in #41 Commerce Recurring fails upon uninstall for me:

    commerce_recurring: The <em class="placeholder">Billing period</em> field type is used in the following fields: commerce_order.billing_period, commerce_order_item.billing_period

    I haven't had much luck uninstalling Commerce Core either.

Production build 0.71.5 2024