2

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?

3

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));
  }
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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