You are here

public function YamlFormTemplatesSubmissionPreviewForm::buildForm in YAML Form 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides YamlFormSubmissionForm::buildForm

File

modules/yamlform_templates/src/YamlFormTemplatesSubmissionPreviewForm.php, line 23

Class

YamlFormTemplatesSubmissionPreviewForm
Preview form submission form.

Namespace

Drupal\yamlform_templates

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  if ($this
    ->isModalDialog()) {

    // Disable validation.
    $form['#attributes']['novalidate'] = 'novalidate';

    // Display form title in modal.
    $form['title'] = [
      '#markup' => $this
        ->getYamlForm()
        ->label(),
      '#prefix' => '<h1>',
      '#suffix' => '</h1>',
      '#weight' => -101,
    ];

    // Remove type from 'actions' and add modal 'actions'.
    unset($form['actions']['#type']);
    $form['modal_actions'] = [
      '#type' => 'actions',
    ];
    $form['modal_actions']['select'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Select'),
      '#url' => Url::fromRoute('entity.yamlform.duplicate_form', [
        'yamlform' => $this
          ->getYamlForm()
          ->id(),
      ]),
      '#attributes' => YamlFormDialogHelper::getModalDialogAttributes(640, [
        'button',
        'button--primary',
      ]),
    ];
    $form['modal_actions']['close'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Close'),
      '#ajax' => [
        'callback' => '::closeDialog',
        'event' => 'click',
      ],
    ];
  }
  return $form;
}