Override remove entities link on module uninstall page When a module needs to be uninstalled, Drupal adds links indicating there is content associated with the module which should be deleted first and provides a link Remove module_name entities. This works fine for most modules, however we have a complex module that needs to perform clean up, is there a way to override this link and have it invoke a custom entity deletion method?
In our case the Remove links that are automatically added to the module uninstall page, don't end up cleaning all items, and leave the site in bad state.
Possibly related to this question asked earlier &quot;How to remove custom module provided entity instances by the time the module being uninstalled?&quot;
If you're solely looking to alter those messages &amp; links, you could to override the required_module_uninstall_validator service with a custom class that extends ContentUninstallValidator and alters its validate() method:
// In your ContentUninstallValidator child class
public function validate($module) {
  $reasons = parent::validate($module);
  // @TODO find/alter the message &amp; link relevant to the module
  return $reasons;
}

However, you'll have to deal with the issue of searching through messages and being able to find the string relevant to the module. This could be problematic depending on how you're searching through the messages array.
A better approach might be to add new messages via a new uninstall validator service that can provide its own custom messages &amp; links that will initiate your own custom entity cleanup code.
A good working example can be seen in the book module:

Defines the service in book.services.yml:

      book.uninstall_validator:
        class: Drupal\book\BookUninstallValidator
        tags:
          - { name: module_install.uninstall_validator }
        arguments: ['@book.outline_storage', '@entity_type.manager', '@string_translation']
        lazy: true


Handles validation &amp; generates new messages in BookUninstallValidator::validate():

    public function validate($module) {
      $reasons = [];
      if ($module == 'book') {
        if ($this
          -&gt;hasBookOutlines()) {
          $reasons[] = $this
            -&gt;t('To uninstall Book, delete all content that is part of a book');
        }
      }
      ...
      return $reasons;
    }