class DefaultConfigProcessor in Translation Management Tool 8
Default implementation of the config processor.
Hierarchy
- class \Drupal\tmgmt_config\DefaultConfigProcessor implements ConfigProcessorInterface
Expanded class hierarchy of DefaultConfigProcessor
1 file declares its use of DefaultConfigProcessor
- ConfigSource.php in sources/
tmgmt_config/ src/ Plugin/ tmgmt/ Source/ ConfigSource.php
File
- sources/
tmgmt_config/ src/ DefaultConfigProcessor.php, line 13
Namespace
Drupal\tmgmt_configView source
class DefaultConfigProcessor implements ConfigProcessorInterface {
/**
* @var \Drupal\config_translation\ConfigMapperInterface
*/
protected $configMapper;
/**
* {@inheritdoc}
*/
public function setConfigMapper(ConfigMapperInterface $config_mapper) {
$this->configMapper = $config_mapper;
}
/**
* {@inheritdoc}
*/
public function extractTranslatables($schema, $config_data, $base_key = '') {
$data = array();
foreach ($schema as $key => $element) {
$element_key = isset($base_key) ? "{$base_key}.{$key}" : $key;
$definition = $element
->getDataDefinition();
// + array('label' => t('N/A'));
if ($element instanceof Mapping || $element instanceof Sequence) {
// Build sub-structure and include it with a wrapper in the form
// if there are any translatable elements there.
$sub_data = $this
->extractTranslatables($element, $config_data[$key], $element_key);
if ($sub_data) {
$data[$key] = $sub_data;
$data[$key]['#label'] = $definition
->getLabel();
}
}
else {
if (!isset($definition['translatable']) || !isset($definition['type']) || empty($config_data[$key])) {
continue;
}
$data[$key] = [
'#label' => $definition['label'],
'#text' => $config_data[$key],
'#translate' => TRUE,
];
}
}
return $data;
}
/**
* {@inheritdoc}
*/
public function convertToTranslation($data) {
$children = Element::children($data);
if ($children) {
$translation = [];
foreach ($children as $name) {
$property_data = $data[$name];
$translation[$name] = $this
->convertToTranslation($property_data);
}
return $translation;
}
elseif (isset($data['#translation']['#text'])) {
return $data['#translation']['#text'];
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultConfigProcessor:: |
protected | property | 1 | |
DefaultConfigProcessor:: |
public | function |
Converts a translated data structure. Overrides ConfigProcessorInterface:: |
1 |
DefaultConfigProcessor:: |
public | function |
Overrides ConfigProcessorInterface:: |
1 |
DefaultConfigProcessor:: |
public | function |
Overrides ConfigProcessorInterface:: |