You are here

public function DefaultConfigProcessor::extractTranslatables in Translation Management Tool 8

Parameters

\Drupal\Core\TypedData\TypedDataInterface[]|\Drupal\Core\Config\Schema\TypedConfigInterface $schema: A list of schema definitions.

$config_data:

string $base_key:

Return value

array

Overrides ConfigProcessorInterface::extractTranslatables

1 method overrides DefaultConfigProcessor::extractTranslatables()
WebformConfigProcessor::extractTranslatables in sources/tmgmt_config/src/WebformConfigProcessor.php

File

sources/tmgmt_config/src/DefaultConfigProcessor.php, line 30

Class

DefaultConfigProcessor
Default implementation of the config processor.

Namespace

Drupal\tmgmt_config

Code

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;
}