function Module::getInstallDirectory

Same name in other branches
  1. 9 core/lib/Drupal/Core/Updater/Module.php \Drupal\Core\Updater\Module::getInstallDirectory()
  2. 10 core/lib/Drupal/Core/Updater/Module.php \Drupal\Core\Updater\Module::getInstallDirectory()
  3. 11.x core/lib/Drupal/Core/Updater/Module.php \Drupal\Core\Updater\Module::getInstallDirectory()

Returns the directory where a module should be installed.

If the module is already installed, drupal_get_path() will return a valid path and we should install it there. If we're installing a new module, we always want it to go into /modules, since that's where all the documentation recommends users install their modules, and there's no way that can conflict on a multi-site installation, since the Update manager won't let you install a new module if it's already found on your system, and if there was a copy in the top-level we'd see it.

Return value

string The absolute path of the directory.

Overrides UpdaterInterface::getInstallDirectory

File

core/lib/Drupal/Core/Updater/Module.php, line 27

Class

Module
Defines a class for updating modules using Drupal\Core\FileTransfer\FileTransfer classes via authorize.php.

Namespace

Drupal\Core\Updater

Code

public function getInstallDirectory() {
    if ($this->isInstalled() && ($relative_path = drupal_get_path('module', $this->name))) {
        // The return value of drupal_get_path() is always relative to the site,
        // so prepend DRUPAL_ROOT.
        return DRUPAL_ROOT . '/' . dirname($relative_path);
    }
    else {
        // When installing a new module, prepend the requested root directory.
        return $this->root . '/' . $this->getRootDirectoryRelativePath();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.