4

This is an issue I've had occasionally when trying to delete a plugin in a custom module. In this example, once a filter format filter plugin has been enabled it's impossible to remove. If you disable it and remove the plugin class from the codebase, it still shows up in the "filter.format.full_html.yml" config.

If you try to edit this file to remove the dependency and then do drush cim, you get an error:

Unexpected error during import with operation update for filter.format.basic_html: The "examplefilter" plugin does not exist.

How do you get rid of this dependency if it shows up in the config when disabled and you can't remove it from the config and import the config without getting a fatal error that the plugin is missing?

1 Answer 1

6

I was able to solve this with an update hook. By deleting the config and then reimporting it this way, it doesn't trigger the unexpected error. You need to run "drush updb" first, before "drush cim" for this to work.

use Drupal\Core\Config\FileStorage;

/**
 * Reimport filter.format.full_html and filter.format.basic_html.
 *
 * This is to remove the dependency on the examplefilter filter
 * which is being deleted.
 */
function mymodule_update_8003() {

  $config_ids = [
    'filter.format.full_html',
    'filter.format.basic_html',
  ];

  foreach ($config_ids as $config_id) {
    Drupal::configFactory()
      ->getEditable($config_id)
      ->delete();

    $config_path = config_get_config_directory('sync');
    $source = new FileStorage($config_path);
    $config_storage = \Drupal::service('config.storage');
    $config_storage->write($config_id, $source->read($config_id));
  }
}
2
  • The issue is so odd ....and still applies in drupal 10.1, but your solution works fine! thx
    – john Smith
    Commented Aug 4, 2023 at 15:26
  • 1
    I actually had the same issue with a D10 upgrade and achieved the same thing as the above update, but with a bash script containing (amongst others) the lines: drush cdel filter.format.basic_html drush cdel filter.format.full_html
    – Geat
    Commented Aug 30, 2023 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.