You are here

public function LingotekConfigManagementForm::debugExport in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8 src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  2. 8.2 src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  3. 4.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  4. 3.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  5. 3.1.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  6. 3.2.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  7. 3.3.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  8. 3.5.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  9. 3.6.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  10. 3.7.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()
  11. 3.8.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::debugExport()

Export source for debugging purposes.

Parameters

\Drupal\config_translation\ConfigMapperInterface $mapper: The mapper.

File

src/Form/LingotekConfigManagementForm.php, line 752

Class

LingotekConfigManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function debugExport(ConfigMapperInterface $mapper, $language, $job_id, &$context) {
  $context['message'] = $this
    ->t('Exporting %label.', [
    '%label' => $mapper
      ->getTitle(),
  ]);
  $profile = $mapper instanceof ConfigEntityMapper ? $this->lingotekConfiguration
    ->getConfigEntityProfile($mapper
    ->getEntity()) : $this->lingotekConfiguration
    ->getConfigProfile($mapper
    ->getPluginId());
  $data = $this->translationService
    ->getConfigSourceData($mapper);
  $data['_debug'] = [
    'title' => trim($mapper
      ->getPluginId() . ' (config): ' . $mapper
      ->getTitle()),
    'profile' => $profile ? $profile
      ->id() : '<null>',
    'source_locale' => $this->translationService
      ->getConfigSourceLocale($mapper),
  ];
  $filename = 'config.' . $mapper
    ->getPluginId() . '.json';
  $plugin_definition = $mapper
    ->getPluginDefinition();
  if (isset($plugin_definition['entity_type']) && 'field_config' === $plugin_definition['entity_type']) {
    $entity = $mapper
      ->getEntity();
    $data['_debug']['title'] = $entity
      ->id() . ' (config): ' . $entity
      ->label();
    $filename = 'config.' . $entity
      ->id() . '.json';
  }
  $source_data = json_encode($data);
  $file = File::create([
    'uid' => 1,
    'filename' => $filename,
    'uri' => 'public://' . $filename,
    'filemime' => 'text/plain',
    'created' => \Drupal::time()
      ->getRequestTime(),
    'changed' => \Drupal::time()
      ->getRequestTime(),
  ]);
  file_put_contents($file
    ->getFileUri(), $source_data);
  $file
    ->save();
  $context['results']['exported'][] = $file
    ->id();
}