You are here

function _potx_load_module_metadata in Translation template extractor 8

Same name and namespace in other branches
  1. 7.3 potx.local.inc \_potx_load_module_metadata()

Load a module's metadata.

The module's metadata includes its dependencies and list of config schema files.

Parameters

string $module_name: The module's name.

Return value

bool TRUE if the module was found, FALSE otherwise.

1 string reference to '_potx_load_module_metadata'
potx_local_init in ./potx.local.inc
Initialize potx to run locally, e.g. by drush.

File

./potx.local.inc, line 228
Hook implementations for this module.

Code

function _potx_load_module_metadata($module_name) {
  global $_potx_found_modules;
  global $_potx_module_metadata;
  if (!isset($_potx_found_modules[$module_name])) {
    return FALSE;
  }
  $module_path = $_potx_found_modules[$module_name]['path'];
  if ($module_name === 'core') {
    $_potx_module_metadata['core']['dependencies'] = [];
  }
  else {
    $info_path = $module_path . '/' . $module_name . '.info.yml';
    $code = file_get_contents($info_path);
    try {
      $info_yaml = Yaml::parse($code);
      $_potx_module_metadata[$module_name]['dependencies'] = isset($info_yaml['dependencies']) ? $info_yaml['dependencies'] : [];
    } catch (ParseException $e) {
      \Drupal::logger('potx')
        ->error("YAML parseing error on file @path: @error", [
        '@path' => $info_path,
        '@error' => $e
          ->getMessage(),
      ]);
      return FALSE;
    }
  }
  $module_files = _potx_explore_dir($module_path . '/config/schema/', '*', POTX_API_8);
  foreach ($module_files as $file_path) {
    if (preg_match('~config/schema/[^/]+\\.yml$~', $file_path)) {
      $_potx_module_metadata[$module_name]['config']['schema'][] = [
        NULL,
        $file_path,
      ];
    }
  }
  return TRUE;
}