You are here

public function ContentSingleExportForm::updateExport in Content Synchronization 8.2

Same name and namespace in other branches
  1. 8 src/Form/ContentSingleExportForm.php \Drupal\content_sync\Form\ContentSingleExportForm::updateExport()
  2. 3.0.x src/Form/ContentSingleExportForm.php \Drupal\content_sync\Form\ContentSingleExportForm::updateExport()

Handles switching the export textarea.

File

src/Form/ContentSingleExportForm.php, line 166

Class

ContentSingleExportForm
Provides a form for exporting a single content file.

Namespace

Drupal\content_sync\Form

Code

public function updateExport($form, FormStateInterface $form_state) {

  // Get submitted values
  $entity_type = $form_state
    ->getValue('content_type');
  $entity_id = $form_state
    ->getValue('content_entity');

  // DB entity to YAML
  $entity = $this->entityTypeManager
    ->getStorage($entity_type)
    ->load($entity_id);

  // Generate the YAML file.
  $serializer_context = [];
  $language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  $entity = $entity
    ->getTranslation($language);
  $exported_entity = $this->contentExporter
    ->exportEntity($entity, $serializer_context);

  // Create the name
  $name = $entity_type . "." . $entity
    ->bundle() . "." . $entity
    ->uuid();

  // Return form values
  $form['export']['#value'] = $exported_entity;
  $form['export']['#description'] = $this
    ->t('Filename: %name', [
    '%name' => $name . '.yml',
  ]);
  return $form['export'];
}