You are here

public function Xml::export in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/tmgmt_file/Format/Xml.php \Drupal\tmgmt_smartling\Plugin\tmgmt_file\Format\Xml::export()
  2. 8 src/Plugin/tmgmt_file/Format/Xml.php \Drupal\tmgmt_smartling\Plugin\tmgmt_file\Format\Xml::export()
  3. 8.2 src/Plugin/tmgmt_file/Format/Xml.php \Drupal\tmgmt_smartling\Plugin\tmgmt_file\Format\Xml::export()

.

Overrides Html::export

File

src/Plugin/tmgmt_file/Format/Xml.php, line 22

Class

Xml
Export into XML.

Namespace

Drupal\tmgmt_smartling\Plugin\tmgmt_file\Format

Code

public function export(JobInterface $job, $conditions = []) {

  // Export job items data without relation to their ids.
  $items = [];
  foreach ($job
    ->getItems($conditions) as $item) {
    $data = \Drupal::service('tmgmt.data')
      ->filterTranslatable($item
      ->getData());
    foreach ($data as $key => $value) {

      // TODO: identical filename task.
      // $items[$item->id()][$this->encodeIdSafeBase64($item->getItemType() . ':' . $item->getItemId() . '][' . $key)] = $value;
      $items[$item
        ->id()][$this
        ->encodeIdSafeBase64($item
        ->id() . '][' . $key)] = $value + [
        'sl-variant' => $item
          ->getItemType() . '-' . $item
          ->getItemId() . '-' . $key,
      ];
    }
  }

  // Avoid rendering with "renderer" service in order to avoid theme debug
  // mode - if it's enabled we shouldn't print debug messages into XML file.
  // Use "twig" service instead.
  $variables = [
    'items' => $items,
  ];
  $theme_registry = theme_get_registry();
  $info = $theme_registry['tmgmt_smartling_xml_template'];
  $template_file = $info['template'] . '.html.twig';
  if (isset($info['path'])) {
    $template_file = $info['path'] . '/' . $template_file;
  }
  return $this
    ->escapePluralStringDelimiter(\Drupal::service('twig')
    ->loadTemplate($template_file)
    ->render($variables));
}