function _potx_process_config_schema in Translation template extractor 8
Same name and namespace in other branches
- 6.3 potx.inc \_potx_process_config_schema()
- 7.3 potx.inc \_potx_process_config_schema()
- 7.2 potx.inc \_potx_process_config_schema()
Recursively process config schema into a flat structure.
This structure is used to extract translatable strings from shipped configuration, and identifies every element by joining all of its parent keys (including itself) separated by the '+' symbol. It stores the schema elements in four sublists: 'translatables': the list of elements that are translatable. 'types': the list of elements that rely on other schema elements for their definition. generally, those with types other than "mapping". 'mappings': the list of elements that have a defined "mapping" property. 'contexts': the list of elements that have a defined context string, using the "translation context" property.
Note that 'types' and 'mappings' lists are not exclusive, i.e. an element can both have a 'type' definition and a separate 'mapping'.
Here is an example config schema: ``` test_schema: type: mapping mapping: name: type: label content: type: text translation context: Test schema content test_filter: type: filter ```
And the resulting processed schema: ``` Array ( [translatables] => Array ( [0] => test_schema+name [1] => test_schema+content )
[types] => Array ( [test_schema+test_filter] => filter )
[mappings] => Array ( [0] => test_schema )
[contexts] => Array ( [test_schema+content] => Test schema content )
) ```
Parameters
string $schema_prefix: All parent keys (including the element's key) joined by '+' symbol, e.g. image.style.*+effects+sequence.
array $schema_data: The schema subtree belonging to the current element.
1 call to _potx_process_config_schema()
- _potx_process_module_schemas in ./
potx.inc - Recursively process and merge the schema required for parsing shipped config.
File
- ./
potx.inc, line 2516 - Extraction API used by the web and command line interface.
Code
function _potx_process_config_schema($schema_prefix, array $schema_data) {
global $_potx_processed_schema;
global $_potx_module_schema;
// Elements can opt out of translation with a 'translatable: false' key.
if (isset($schema_data['translatable']) && $schema_data['translatable'] === FALSE) {
return;
}
// Do not process elements without a type, since the locale module strictly
// requires translatable elements to be of base type 'string', and also we
// can't traverse an element without knowing its type.
if (!isset($schema_data['type'])) {
return;
}
$type = $schema_data['type'];
if (isset($schema_data['mapping'])) {
foreach ($schema_data['mapping'] as $key => $element_data) {
$element_key = $schema_prefix . '+' . $key;
_potx_process_config_schema($element_key, $element_data);
}
if ($type != 'mapping') {
$_potx_processed_schema['types'][$schema_prefix] = $type;
$_potx_module_schema['types'][$schema_prefix] = $type;
}
$_potx_processed_schema['mappings'][] = $schema_prefix;
$_potx_module_schema['mappings'][] = $schema_prefix;
}
else {
if ($type == 'sequence') {
if (!isset($schema_data['sequence'])) {
return;
}
$sequence_schema = isset($schema_data['sequence'][0]) ? $schema_data['sequence'][0] : $schema_data['sequence'];
_potx_process_config_schema($schema_prefix . '+sequence', $sequence_schema);
$_potx_processed_schema['types'][$schema_prefix] = 'sequence';
$_potx_module_schema['types'][$schema_prefix] = 'sequence';
}
elseif (in_array($type, $_potx_processed_schema['translatables']) || isset($schema_data['translatable']) && $schema_data['translatable'] === TRUE) {
$_potx_processed_schema['translatables'][] = $schema_prefix;
$_potx_module_schema['translatables'][] = $schema_prefix;
// Elements can define a context string, or inherit the context from their
// defined type.
if (isset($schema_data['translation context'])) {
$_potx_processed_schema['contexts'][$schema_prefix] = $schema_data['translation context'];
$_potx_module_schema['contexts'][$schema_prefix] = $schema_data['translation context'];
}
elseif (isset($_potx_processed_schema['contexts'][$type])) {
$_potx_processed_schema['contexts'][$schema_prefix] = $_potx_processed_schema['contexts'][$type];
$_potx_module_schema['contexts'][$schema_prefix] = $_potx_processed_schema['contexts'][$type];
}
}
else {
$_potx_processed_schema['types'][$schema_prefix] = $type;
$_potx_module_schema['types'][$schema_prefix] = $type;
}
}
}