How to add warning message before module is uninstalled The module in question has a content entity, entity1, that has another content entity, entity2, that depends on entity1. I would like to add a warning before uninstall of the module if there are currently entity2's that exist and that depend on entity1. The warning will suggest to delete the entity2 and then entity1 before the module can be uninstalled. How could I do this?
Before a module is uninstalled, Drupal invokes all the services implementing UninstallValidatorInterface and tagged with module_install.uninstall_validator. Their validate() method (see BookUninstallValidator::validate(), for example) returns an array of strings explaining why the module cannot be uninstalled, which are then shown in the user interface.

Notice that the validate() method receives the name of the module as parameter. While normally the module implementing the UninstallValidatorInterface service checks if itself can be uninstalled, a UninstallValidatorInterface service can avoid any module is uninstalled.

In Drupal 7, there isn't anything similar. The only way to achieve this is altering the page showing the list of the installed modules to show a message near a module.