You are here

public function WebformTemplatesSubmissionPreviewForm::buildForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_templates/src/WebformTemplatesSubmissionPreviewForm.php \Drupal\webform_templates\WebformTemplatesSubmissionPreviewForm::buildForm()

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 WebformSubmissionForm::buildForm

File

modules/webform_templates/src/WebformTemplatesSubmissionPreviewForm.php, line 21

Class

WebformTemplatesSubmissionPreviewForm
Preview webform submission webform.

Namespace

Drupal\webform_templates

Code

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

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

    // Display webform title in modal.
    $form['title'] = [
      '#markup' => $this
        ->getWebform()
        ->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.webform.duplicate_form', [
        'webform' => $this
          ->getWebform()
          ->id(),
      ]),
      '#attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW, [
        'button',
        'button--primary',
      ]),
    ];
    $form['modal_actions']['close'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Close'),
      '#ajax' => [
        'callback' => '::closeDialog',
        'event' => 'click',
      ],
    ];
  }
  return $form;
}