You are here

public function ContentSingleExportForm::updateExport in Content Synchronization 8

Same name and namespace in other branches
  1. 8.2 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 170

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_bundle = $form_state
    ->getValue('content_name');
  $entity_id = $form_state
    ->getValue('content_entity');

  // DB entity to YAML
  module_load_include('inc', 'content_sync', 'content_sync.batch');
  $entity = _content_sync_db_to_entity($entity_type, $entity_bundle, $entity_id);
  $output = Yaml::encode($entity);
  $name = $entity_type . "." . $entity_bundle . "." . $entity['values'][0]['uuid'][0]['value'];

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