Add helpers to remove leftover field storage config

Created on 10 April 2024, 3 months ago
Updated 12 April 2024, 3 months ago

The issue of πŸ’¬ How to fix "non-existent config entity name returned by FieldStorageConfigInterface::getBundles()" Needs work keeps coming up for old sites, it would be nice to have the tools to fix, covered extensively in that issue, packaged up and readily available. This seems like a sensible module to house it.

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

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

Comments & Activities

  • Issue created by @mlncn
    • mlncn β†’ committed 11b087b6 on 1.0.x
      Issue #3439991 by mlncn: Add helpers to remove leftover field storage...
    • mlncn β†’ committed 9da82eb6 on 1.0.x
      Make service name consistent with class name
      
      Really wanted to make it...
  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    Example of usage in an example.install:

    /**
     * Remove ghostly remains of old 'resources' content type (renamed resource).
     *
     * Implements hook_update_N().
     */
    function example_update_9002() {
      \Drupal::service('module_installer')->install(['migration_helpers']);
      \Drupal::service('migration_helpers.exorcise_ghost_config_entity')->removeBundleFromFieldStorageConfig('node', 'resources');
      \Drupal::service('module_installer')->uninstall(['migration_helpers']);
    }                           
    
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    Really need to stress that none of this code checks if what it is removing is safe to remove. It will totally remove a completely still-in-use set of config. That it is truly no longer of use is an exercise for the user of this code.

  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    Two additional methods on ExorciseGhostConfigEntity:

    1. removeFieldStorageConfig($entity_type, $bundle, $field_name)
    2. cleanUpEmptyEntityType($entity_type)

    The latter is called by removeBundleFromFieldStorageConfig($entity_type, $bundle) automatically.

Production build 0.69.0 2024