You are here

public function LingotekManagementForm::debugExport in Lingotek Translation 8

Export source for debugging purposes.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.

File

src/Form/LingotekManagementForm.php, line 679
Contains \Drupal\Lingotek\Form\LingotekManagementForm.

Class

LingotekManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function debugExport(ContentEntityInterface $entity, &$context) {
  $context['message'] = $this
    ->t('Exporting @type %label.', [
    '@type' => $entity
      ->getEntityType()
      ->getLabel(),
    '%label' => $entity
      ->label(),
  ]);
  if ($profile = $this->lingotekConfiguration
    ->getEntityProfile($entity, FALSE)) {
    $data = $this->translationService
      ->getSourceData($entity);
    $data['_debug'] = [
      'title' => $entity
        ->bundle() . ' (' . $entity
        ->getEntityTypeId() . '): ' . $entity
        ->label(),
      'profile' => $profile ? $profile
        ->id() : '<null>',
      'source_locale' => $this->translationService
        ->getSourceLocale($entity),
    ];
    $source_data = json_encode($data);
    $filename = $entity
      ->getEntityTypeId() . '.' . $entity
      ->bundle() . '.' . $entity
      ->id() . '.json';
    $file = File::create([
      'uid' => 1,
      'filename' => $filename,
      'uri' => 'public://' . $filename,
      'filemime' => 'text/plain',
      'created' => REQUEST_TIME,
      'changed' => REQUEST_TIME,
    ]);
    file_put_contents($file
      ->getFileUri(), $source_data);
    $file
      ->save();
    $context['results']['exported'][] = $file
      ->id();
  }
  else {
    $bundleInfos = $this->entityManager
      ->getBundleInfo($entity
      ->getEntityTypeId());
    drupal_set_message($this
      ->t('The @type %label has no profile assigned so it was not processed.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
    ]), 'warning');
  }
}