You are here

public function TourBuilderExportForm::form in Tour Builder 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/TourBuilderExportForm.php, line 60

Class

TourBuilderExportForm
Form controller for the tour entity clone form.

Namespace

Drupal\tour_builder\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $definition = $this->entityTypeManager
    ->getDefinition('tour');
  $name = $definition
    ->getConfigPrefix() . '.' . $this->entity
    ->getOriginalId();
  $config = $this->configStorage
    ->read($name);
  $unset_keys = [
    'uuid',
    '_core',
  ];
  foreach ($unset_keys as $key) {
    unset($config[$key]);
  }
  $content = Yaml::encode($config);

  // $filename = $name . '.yml';
  // $path = 'temporary://' . $filename;
  // //$link = \Drupal::l($name, Url::fromUri($path));
  // file_put_contents($path, $content);
  // $form['link'] = array(
  // '#type' => 'item',
  // '#title' => $this->t('Download'),
  // '#description' => 'Right click to download.',
  // '#markup' => $link,
  // );
  $form['export'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('YAML Content'),
    '#description' => $this
      ->t('Filename: %name', [
      '%name' => $name . '.yml',
    ]),
    '#rows' => 15,
    '#default_value' => $content,
  ];
  return $form;
}