public function FieldsSettingsForm::validateForm in Diff 8
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ FieldsSettingsForm.php, line 395
Class
- FieldsSettingsForm
- Configure fields with their diff builder plugin settings.
Namespace
Drupal\diff\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$form_values = $form_state
->getValues();
$plugin_settings = $form_state
->get('plugin_settings');
$fields = $form_values['fields'];
foreach ($fields as $field_key => $field_values) {
// Validate only non-null plugins.
if ($field_values['plugin']['type'] != 'hidden') {
$settings = array();
$key = NULL;
// Form submitted without pressing update button on plugin settings form.
if (isset($field_values['settings_edit_form']['settings'])) {
$settings = $field_values['settings_edit_form']['settings'];
$key = 1;
}
elseif (isset($plugin_settings[$field_key]['settings'])) {
$settings = $plugin_settings[$field_key]['settings'];
$key = 2;
}
if (!empty($settings)) {
// Build a new Form State object and populate it with values.
$state = new FormState();
$state
->setValues($settings);
$state
->set('fields', $field_key);
$plugin = $this->diffBuilderManager
->createInstance($field_values['plugin']['type'], []);
// Send the values to the plugins form validate handler.
$plugin
->validateConfigurationForm($form, $state);
// Assign the validation messages back to the big table.
if ($key == 1) {
$form_state
->setValue([
'fields',
$field_key,
'settings_edit_form',
'settings',
], $state
->getValues());
}
elseif ($key == 2) {
$form_state
->set([
'plugin_settings',
$field_key,
'settings',
], $state
->getValues());
}
}
}
}
}