You are here

function _potx_find_all_modules in Translation template extractor 7.3

Same name and namespace in other branches
  1. 8 potx.local.inc \_potx_find_all_modules()

Find all available modules based on Drupal 8's directory structure.

Parameters

string $module_path: Path to the module that is being parsed by potx.

1 call to _potx_find_all_modules()
potx_local_init in ./potx.local.inc
Initialize potx to run locally, e.g. by drush.

File

./potx.local.inc, line 43

Code

function _potx_find_all_modules($module_path) {
  global $_potx_found_modules;
  $module_path = realpath($module_path);
  if (substr($module_path, -1) != '/') {
    $module_path = $module_path . '/';
  }

  // The list of directories to check in the path, to find out if we are in a Drupal install directory.
  $checks = array(
    '/sites/',
    '/core/',
    '/profiles/',
    '/modules/',
    '/themes/',
  );

  // The list of paths that could contain "modules/" or "themes/" subdirectories.
  $search_paths = array();
  foreach ($checks as $check) {
    if (preg_match("!{$check}!", $module_path)) {
      $parts = explode($check, $module_path, 2);

      // The installed Drupal root.
      $root = $parts[0];

      // The Drupal core directory contains a config/schema subdirectory, which
      //  is not part of any module or theme.
      $_potx_found_modules['core']['path'] = $root . '/core';
      $search_paths[] = $root;
      $search_paths[] = $root . '/core';
      $profiles = glob($root . '/profiles/*', GLOB_ONLYDIR);
      $sites = glob($root . '/sites/*', GLOB_ONLYDIR);
      if (is_array($profiles)) {
        $search_paths = array_merge($search_paths, $profiles);
      }
      if (is_array($sites)) {
        $search_paths = array_merge($search_paths, $sites);
      }
      break;
    }
  }
  foreach ($search_paths as $search_path) {
    foreach (array(
      '/modules',
      '/themes',
    ) as $sub) {
      if (is_dir($search_path . $sub)) {
        _potx_find_modules($search_path . $sub);
      }
    }
  }
}