You are here

function _potx_build_reverse_lookup in Translation template extractor 8

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

Build a lookup table for config schema's matching keys and their modules.

Builds the reverse lookup table from config schemas' matching keys, and their containing modules, for all modules found locally. This is only used on a local potx. Building the reverse lookup table is expensive, so it is delayed as much as possible, i.e. until an optional config is parsed, and the reverse lookup is called.

See also

_potx_find_all_modules()

_potx_schema_reverse_lookup()

1 call to _potx_build_reverse_lookup()
_potx_schema_reverse_lookup in ./potx.local.inc
Find the module containing the schema for a specific config file.

File

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

Code

function _potx_build_reverse_lookup() {
  global $_potx_reverse_lookup_built;
  global $_potx_found_modules;
  global $_potx_callbacks;
  foreach ($_potx_found_modules as $module_name => $module_data) {
    $module_files = _potx_explore_dir($module_data['path'] . '/', '*', POTX_API_8);
    foreach ($module_files as $file_name) {
      if (preg_match('~config/schema/[^/]+\\.yml$~', $file_name)) {
        $code = file_get_contents($file_name);
        try {
          $yaml = Yaml::parse($code);
          if (is_array($yaml)) {
            $keys = array_keys($yaml);
            $_potx_callbacks['schema_store_lookup']($keys, $module_name);
          }
        } catch (ParseException $e) {
          \Drupal::logger('potx')
            ->error("YAML parseing error on file @path: @error", [
            '@path' => $file_name,
            '@error' => $e
              ->getMessage(),
          ]);
        }
      }
    }
  }
  $_potx_reverse_lookup_built = TRUE;
}