MOVE A DRUPAL MODULE TO ANOTHER DIRECTORY

In some cases it is necessary to move a module already installed in Drupal to another directory.

To give some examples:

  • You want to have all modules that have some patch applied in a separate directory to facilitate future maintenance.
  • You want to move a custom module that you put by mistake in the modules /contrib directory (this happens a lot when you inherit a project made by another agency or freelancer)
  • You have published on drupal.org a module you have made. This means that it should now be in the /contrib directory and not in the /custom directory. 
  • Convert a Drupal that uses a distribution to a normal Drupal without a distribution.
  • Or any case that makes you move some module in a place where it was not before.

In theory, and according to the documentation, just move the code to the new directory and then clear the caches.

But there are several problems to take into account:

  • Emptying the caches from the web UI is going to be impossible. The web is broken by not detecting the module. Therefore you are forced to clear the caches from the command line. This can be a problem for websites hosted on cheap hostings where you don't have SSH or Drush access. This forces you to make the changes locally and resubmit the database.
  • The server's Drush is sometimes out of date and does not remove all caches.

So what is the right way to do it without breaking the site?

You have to move the module to its new directory, and then clear the caches with one of the following ways:

Use "drupal cr" instead of "drush cr" (it's the one that worked best for me).

Use the drush from inside vendor and not the one from server. "./vendor/bin/drush cr"

Have Any Project in Mind?

If you want to do something in Drupal maybe you can hire me.

Either for consulting, development or maintenance of Drupal websites.