public function WebformConfigProcessor::extractTranslatables

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 DefaultConfigProcessor::extractTranslatables

File

sources/tmgmt_config/src/WebformConfigProcessor.php, line 26

Class

WebformConfigProcessor

Namespace

Drupal\tmgmt_config

Code

public function extractTranslatables($schema, $config_data, $base_key = '') {
  $data = array();
  foreach ($schema as $key => $element) {
    if ($key == 'elements' && empty($base_key)) {
      $webform = $this->configMapper
        ->getEntity();
      $translation_manager = \Drupal::service('webform.translation_manager');
      $source_elements = $translation_manager
        ->getSourceElements($webform);
      $data[$key] = $this
        ->convertElementsToData($source_elements);
      $data[$key]['#label'] = t('Elements');
      continue;
    }
    $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] = array(
        '#label' => $definition['label'],
        '#text' => $config_data[$key],
        '#translate' => $this
          ->isTranslatable($config_data[$key]),
      );
    }
  }
  return $data;
}