You are here

function _potx_process_module_schemas in Translation template extractor 7.3

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

Recursively process and merge the schemas required for parsing shipped config.

Handles module dependencies, and config optional dependencies.

Parameters

array $module_list: The list of modules that their schema should be processed.

1 call to _potx_process_module_schemas()
_potx_parse_shipped_configuration in ./potx.inc
Parse shipped configuration for translatables. Drupal 8+

File

./potx.inc, line 2662
Extraction API used by the web and command line interface.

Code

function _potx_process_module_schemas($module_list) {
  global $_potx_module_metadata;
  global $_potx_processed_modules;
  global $_potx_module_schema;
  global $potx_callbacks;

  // Remove modules that have already been processed.
  $module_list = array_diff($module_list, $_potx_processed_modules);
  if (count($module_list) == 0) {
    return;
  }

  // Mark as processed early, to prevent a loop while traversing dependency graph.
  $_potx_processed_modules = array_merge($_potx_processed_modules, $module_list);
  $dependencies = array();

  // Gather list of all dependencies for the current $module_list.
  foreach ($module_list as $module_name) {

    // If the module is directly available from the initial given path, their
    //  metadata is already available.
    if (isset($_potx_module_metadata[$module_name])) {
      if (!empty($_potx_module_metadata[$module_name]['dependencies'])) {
        $dependencies = array_merge($dependencies, $_potx_module_metadata[$module_name]['dependencies']);
      }
    }
    else {

      // Try to load the module metadata from the globally available modules
      //  (e.g. drupal install directory in local potx, database in l10n_server)
      if ($potx_callbacks['load_module_metadata']($module_name)) {
        $dependencies = array_merge($dependencies, $_potx_module_metadata[$module_name]['dependencies']);
      }
    }
  }
  if (!empty($dependencies)) {

    // Process schema for dependencies first.
    _potx_process_module_schemas($dependencies);
  }

  // If the schema for a module is already available, merge it.
  foreach ($module_list as $module_name) {
    $module_schema = $potx_callbacks['schema_load']($module_name);

    // If the module is not in the current parsed project, and its config schema can be found in the database
    if (!isset($_potx_module_metadata[$module_name]['config']['schema']) && $module_schema !== NULL) {

      // If its config schema isn't empty
      if (!empty($module_schema['types'])) {
        _potx_merge_processed_schema($module_schema);
      }

      // Remove from list of unprocessed modules.
      unset($module_list[array_search($module_name, $module_list)]);
    }
  }
  foreach ($module_list as $module_name) {
    if (!empty($_potx_module_metadata[$module_name]['config']['schema'])) {
      $_potx_module_schema = array(
        'translatables' => array(),
        'types' => array(),
        'mappings' => array(),
        'contexts' => array(),
      );
      foreach ($_potx_module_metadata[$module_name]['config']['schema'] as $file_paths) {
        $yaml = _potx_parse_yaml($file_paths[1]);
        if ($yaml === NULL) {
          continue;
        }
        foreach ($yaml as $key => $element) {
          _potx_process_config_schema($key, $element);
        }
      }
      $potx_callbacks['schema_store']($module_name);
    }
  }
}