YamlFormTemplatesSubmissionPreviewForm.php in YAML Form 8
File
modules/yamlform_templates/src/YamlFormTemplatesSubmissionPreviewForm.php
View source
<?php
namespace Drupal\yamlform_templates;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CloseDialogCommand;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\yamlform\Utility\YamlFormDialogHelper;
use Drupal\yamlform\YamlFormDialogTrait;
use Drupal\yamlform\YamlFormSubmissionForm;
class YamlFormTemplatesSubmissionPreviewForm extends YamlFormSubmissionForm {
use YamlFormDialogTrait;
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
if ($this
->isModalDialog()) {
$form['#attributes']['novalidate'] = 'novalidate';
$form['title'] = [
'#markup' => $this
->getYamlForm()
->label(),
'#prefix' => '<h1>',
'#suffix' => '</h1>',
'#weight' => -101,
];
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;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($this
->isModalDialog()) {
$form_state
->clearErrors();
}
else {
parent::validateForm($form, $form_state);
}
}
public function closeDialog(array &$form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$response
->addCommand(new CloseDialogCommand());
return $response;
}
}