public function OverrideWebformVariant::validateConfigurationForm in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformVariant/OverrideWebformVariant.php \Drupal\webform\Plugin\WebformVariant\OverrideWebformVariant::validateConfigurationForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Overrides WebformVariantBase::validateConfigurationForm
File
- src/
Plugin/ WebformVariant/ OverrideWebformVariant.php, line 137
Class
- OverrideWebformVariant
- Webform override variant.
Namespace
Drupal\webform\Plugin\WebformVariantCode
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
$webform = $this
->getWebform();
$values = $form_state
->getValues();
// Validate settings names.
$settings = $webform
->getSettings();
foreach ($values['settings'] as $setting_name => $setting_value) {
if (!isset($settings[$setting_name])) {
$form_state
->setErrorByName('settings', $this
->t('Setting %name is not a valid setting name.', [
'%name' => $setting_name,
]));
}
}
// Validate element keys.
$elements = Yaml::decode($values['elements']) ?: [];
if ($elements) {
foreach ($elements as $element_key => $element_properties) {
// Skip custom form property.
if (WebformElementHelper::property($element_key)) {
continue;
}
$element = $webform
->getElement($element_key);
if (!$element) {
$form_state
->setErrorByName('elements', $this
->t('Element %key is not a valid element key.', [
'%key' => $element_key,
]));
}
}
}
// Validate handler ids.
foreach ($values['handlers'] as $handler_id => $handler_configuration) {
if (!$webform
->getHandlers()
->has($handler_id)) {
$form_state
->setErrorByName('handlers', $this
->t('Handler %id is not a valid handler id.', [
'%id' => $handler_id,
]));
}
}
}