You are here

public function ModuleFileWriter::getRelativeModuleFolder in Module Builder 8.3

Get the Drupal-relative path of the module folder to write to.

This considers the following options, in order:

  • The location of an existing module of the given name.
  • Inside the 'modules/custom' folder, if it exists.
  • Inside the 'modules' folder.

Parameters

string $module_name: The module machine name to get the path for.

Return value

string The Drupal-relative path of the module folder. This does not yet necessarily exist.

1 method overrides ModuleFileWriter::getRelativeModuleFolder()
ModuleFileWriterDummyLocation::getRelativeModuleFolder in tests/modules/test_dummy_module_write_location/src/ModuleFileWriterDummyLocation.php
Put modules in the site folder, as that gets cleaned up.

File

src/ModuleFileWriter.php, line 58

Class

ModuleFileWriter
Writes module files.

Namespace

Drupal\module_builder

Code

public function getRelativeModuleFolder($module_name) {

  // If the module folder already exists, write there.
  $exists = \Drupal::service('extension.list.module')
    ->exists($module_name);
  if ($exists) {
    $module = \Drupal::service('extension.list.module')
      ->get($module_name);
    return $module
      ->getPath();
  }
  if (file_exists('modules/custom')) {
    $modules_dir = 'modules/custom';
  }
  else {
    $modules_dir = 'modules';
  }
  $drupal_relative_module_dir = $modules_dir . '/' . $module_name;
  return $drupal_relative_module_dir;
}