-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHandlerConfigurationValidationForm.php
More file actions
79 lines (69 loc) · 2.39 KB
/
Copy pathHandlerConfigurationValidationForm.php
File metadata and controls
79 lines (69 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Drupal\os2forms\Form;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformState;
use Drupal\webform\Plugin\WebformHandlerInterface;
/**
* Form used for programmatically validating webform handler configurations.
*
* Building the form populates all elements with their default values, i.e.
* the stored handler configuration, and submitting the form programmatically
* with no input validates the configuration against the current webform
* state (cf. \Drupal\Core\Form\FormBuilder::submitForm()).
*
* The real handler edit form cannot be used for this as submitting
* \Drupal\webform\Form\WebformHandlerFormBase updates and saves the webform.
*
* @see \Drupal\os2forms\Helper\HandlerConfigurationValidator
*/
class HandlerConfigurationValidationForm implements FormInterface {
/**
* Constructs a HandlerConfigurationValidationForm.
*
* @param \Drupal\webform\Plugin\WebformHandlerInterface $handler
* The webform handler whose configuration to validate.
*/
public function __construct(
private readonly WebformHandlerInterface $handler,
) {
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'os2forms_handler_configuration_validation_form';
}
/**
* {@inheritdoc}
*
* @phpstan-param array<string, mixed> $form
* @phpstan-return array<string, mixed>
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Build the handler configuration form the same way as
// \Drupal\webform\Form\WebformHandlerFormBase::form().
$form['settings'] = [];
$subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
$form['settings'] = $this->handler->buildConfigurationForm($form['settings'], $subform_state);
$form['settings']['#tree'] = TRUE;
return $form;
}
/**
* {@inheritdoc}
*
* @phpstan-param array<string, mixed> $form
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
$this->handler->validateConfigurationForm($form, $subform_state);
}
/**
* {@inheritdoc}
*
* @phpstan-param array<string, mixed> $form
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Intentionally empty: this form is only used for validation.
}
}