I tried the Drupal 8 version of the Mass Contact module (8.x-1.0-beta2, released on June 2017).

As I was not fully satisfied, I decided to uninstall it.
Once done, I got errors when I tried editing a user account.

The website encountered an unexpected error. Please try again later.
Error: Call to undefined function mass_contact_opt_out_allowed_values_callback() in options_allowed_values() (line 89 of core/modules/options/options.module).

Digging a little bit, I found that the code to uninstall the module was not fully implemented: it leaves (at least) two configurations (field.field.user.user.mass_contact_opt_out and field.storage.user.mass_contact_opt_out) and a table in the database (d8_user__mass_contact_opt_out).

How can I get rid of that and have a clean uninstall?


This is an issue already resolved for the 8.x-1.x branch, as reported in Uninstall should remove mass_contact_opt_out field.

The code that has been added to the uninstall hook is the following one.


If you have Drush installed, you can write those two lines in a file (for example, fix-module.php) and run it with drush php-script fix.module.php. You can also put the following code in a file next to the authorize.php file that comes with Drupal core, and access that file from the browser.

use Drupal\Core\DrupalKernel;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

// Change the directory to the Drupal root.
$autoloader = (require_once 'autoload.php');

try {
  $request = Request::createFromGlobals();
  $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
} catch (HttpExceptionInterface $e) {
  $response = new Response('', $e->getStatusCode());
  • I tried to do it with drush php-script fix.module.php but nothing changed (I don't know what I did wrong). So I did it with drush config:delete and there it worked! No more error message when trying to edit a User. But (there is a but) now I have an error in my Status report: Field user.mass_contact_opt_out needs to be uninstalled. How can I do that? – gbmapo Dec 15 '19 at 7:42
  • And I still found references to field.field.user.user.mass_contact_opt_out in some config files: core.entity_form_display.user.user.default, core.entity_view_display.user.user.compact, core.entity_view_display.user.user.default, field.field.user.user.mass_contact_opt_out, field.storage.user.mass_contact_opt_out. – gbmapo Dec 15 '19 at 7:58

Yes, this function is defined in configuration. You should find all occurrences of the function name by a full text search of the exported configuration:


  allowed_values_function: 'examplemodule_allowed_values_callback'

More info How do I programmatically update the allowed values of a list field?

Then you can either remove the function name from the field config (in case you want to keep the field data) or remove the field config and field storage yaml files to delete the field data on the next config import. If you have still configured the field in display modes, you get an error when importing, then remove all references of the field in the config files mentioned in the error message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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