You are here

function _potx_parse_shipped_configuration in Translation template extractor 8

Same name and namespace in other branches
  1. 6.3 potx.inc \_potx_parse_shipped_configuration()
  2. 7.3 potx.inc \_potx_parse_shipped_configuration()
  3. 7.2 potx.inc \_potx_parse_shipped_configuration()

Parse shipped configuration for translatables. Drupal 8+.

Parameters

string $save_callback: Callback function used to save strings.

int $api_version: Drupal API version to work with.

2 calls to _potx_parse_shipped_configuration()
PotxTest::testDrupal8ShippedConfiguration in tests/src/Kernel/PotxTest.php
Test parsing of Drupal 8 shipped configuration files.
potx_finish_processing in ./potx.inc
Executes tasks that need to happen after all the files have been processed.

File

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

Code

function _potx_parse_shipped_configuration($save_callback = '_potx_save_string', $api_version = POTX_API_CURRENT) {
  global $_potx_module_metadata;
  global $_potx_processed_schema;
  global $_potx_processed_modules;
  global $_potx_callbacks;
  foreach ($_potx_module_metadata as $module_name => $module_metadata) {

    // Reset the processed schema for every module.
    $_potx_processed_modules = [];
    $_potx_processed_schema = [
      'translatables' => [],
      'types' => [],
      'mappings' => [],
      'contexts' => [],
    ];

    // "core" contains the base data type and translatable definitions.
    _potx_process_module_schemas([
      'core',
    ]);
    _potx_process_module_schemas([
      $module_name,
    ]);
    if (isset($module_metadata['config']['install'])) {
      foreach ($module_metadata['config']['install'] as $config_paths) {
        $parsed_config = _potx_parse_yaml($config_paths[1]);
        if ($parsed_config === NULL) {
          continue;
        }

        // Dependencies defined in a config file itself should not be visible
        // to other config files. So, make a temp copy here, and revert after
        // parsing the config file.
        $temp = $_potx_processed_schema;
        if (isset($parsed_config['dependencies']['module'])) {
          _potx_process_module_schemas($parsed_config['dependencies']['module']);
        }

        // Find the schema that matches the config file.
        $path_info = pathinfo($config_paths[1]);
        $config_name = $path_info['filename'];
        $schema = _potx_find_matching_schema($config_name);
        if ($schema !== NULL) {
          _potx_find_shipped_config_translatables($parsed_config, $schema, NULL, NULL, $config_paths[0], $save_callback);
        }
        $_potx_processed_schema = $temp;
      }
    }
    if (isset($module_metadata['config']['optional'])) {

      // Optional configs are different, since they do not explicitly specify
      // which module they belong to.
      foreach ($module_metadata['config']['optional'] as $config_paths) {
        $_potx_processed_modules = [];
        $_potx_processed_schema = [
          'translatables' => [],
          'types' => [],
          'mappings' => [],
          'contexts' => [],
        ];
        _potx_process_module_schemas([
          'core',
        ]);

        // Find the schema that matches the config file.
        $path_info = pathinfo($config_paths[1]);
        $config_name = $path_info['filename'];
        $parsed_config = _potx_parse_yaml($config_paths[1]);
        if ($parsed_config === NULL) {
          continue;
        }
        $match_candidates = _potx_find_matching_schema_candidates($config_name);
        $matched = $_potx_callbacks['schema_reverse_lookup']($match_candidates);
        if ($matched === NULL) {
          continue;
        }
        _potx_process_module_schemas([
          $matched,
        ]);
        if (isset($parsed_config['dependencies']['module'])) {
          _potx_process_module_schemas($parsed_config['dependencies']['module']);
        }
        $schema = _potx_find_matching_schema($config_name);
        _potx_find_shipped_config_translatables($parsed_config, $schema, NULL, NULL, $config_paths[0], $save_callback);
      }
    }
  }
}