Drupal 11: Remove Third Party Settings From Field Configuration

Third party settings in Drupal are very useful, but once you have installed them it can be a bit of a pain to remove them. They might be plugged into lots of different config files and some modules don't provide mechanisms to remove them once installed. This means that if you remove the module the third party settings might stick around and do nothing.

To remove third party settings from your site can either hand edit the configuration files (which I don't advise doing) or use an update hook to remove the settings from the configuration.

The following update hook assumes you need to remove the third party settings my_module:some-setting from your field config.

/**
 * Remove all of the my_module:some-setting config from the site.
 */
function my_module_update_11001(&$sandbox = NULL) {
  $fieldEntities = \Drupal::entityTypeManager()->getStorage('field_config')->loadMultiple();

  foreach ($fieldEntities as $fieldId => $field) {
    $fieldEntities[$fieldId]->unsetThirdPartySetting('my_module', 'some-setting');
    $fieldEntities[$fieldId]->save();
  }
}

Once you have run this update hook you just need to export the configuration of your site and you will see the third party settings being removed.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
2 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.