I'm trying to port 'module_install' module from drupal 7 to 8, which installs a module in a specific directory. To specific the install directory, the module creates a class which extends from ModuleUpdater, and override the getInstallDirectory. Here is the code in Drupal 7:

/**
* Implements hook_updater_info_alter().
**/
function module_install_updater_info_alter(&$updaters) {
   $updaters['module']['class'] = 'ModuleInstallUpdater';
}

ModuleInstallUpdater class:

/**
 * @file
 * Subclasses of the ModuleUpdater class to update modules.
 */

module_load_include('inc', 'module_install', 'module_install.api');
module_load_include('inc', 'system', 'system.updater');

/**
 * Extends the default ModuleUpdater to change the destination install path.
 */
class ModuleInstallUpdater extends ModuleUpdater {

  /**
   * Returns the install directory.
   *
   * @return string
   *   The path to the install directory.
   */
  public function getInstallDirectory() {
    if ($relative_path = drupal_get_path('module', $this->name)) {
      $relative_path = dirname($relative_path);
    }
    else {
      $relative_path = module_install_get_destination_choice('modules');
    }
    return DRUPAL_ROOT . '/' . $relative_path;
  }
}

And for Drupal 8, I use Updater class to do the same, since was ModuleUpdater was removed. So this is the code for Drupal 8 module (just changes the extend class):

/**
* Implements hook_updater_info_alter().
**/
function module_install_updater_info_alter(&$updaters) {
   $updaters['module']['class'] = 'ModuleInstallUpdater';
}

ModuleInstallUpdater class:

<?php
/**
 * @file
 * Subclasses of the ModuleUpdater class to update modules.
 */

module_load_include('inc', 'module_install', 'module_install.api');
module_load_include('inc', 'system', 'system.updater');

use Drupal\Core\Updater;

/**
 * Extends the default ModuleUpdater to change the destination install path.
 */
class ModuleInstallUpdater extends Module {

  /**
   * Returns the install directory.
   *
   * @return string
   *   The path to the install directory.
   */
  public function getInstallDirectory() {
    if ($relative_path = drupal_get_path('module', $this->name)) {
      $relative_path = dirname($relative_path);
      \Drupal::logger('my_module')->notice('Lehenengoa');
    }
    else {
      $relative_path = module_install_get_destination_choice('modules');
      \Drupal::logger('my_module')->notice('Bigarrengoa');
    }
    return DRUPAL_ROOT . '/' . $relative_path;
  }
}

But it doesn't find the ModuleInstallUpdater class:

call_user_func() expects parameter 1 to be a valid callback, class 'ModuleInstallUpdater' not found in Drupal\Core\Updater\Updater::getUpdaterFromDirectory() (line 88 of C:\Users\julen\Sites\devdesktop\drupal-8.6.1\core\lib\Drupal\Core\Updater\Updater.php)

Can someone help me with this?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.