public function TransactorBase::validateConfigurationForm in Transaction 8
Handles the validation for the transactor plugin settings form.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Overrides PluginFormInterface::validateConfigurationForm
File
- src/
TransactorBase.php, line 680
Class
- TransactorBase
- Provides a base class for transactor plugins.
Namespace
Drupal\transactionCode
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// Validate field mapping.
$values = $form_state
->getValues();
$field_names = [];
foreach ($values as $key => $value) {
if (empty($value) || !($field_info = $form_state
->getTemporaryValue('field_info_' . $key))) {
// No value or not a field.
continue;
}
// Validate new fields.
if ($value === '_create') {
$machine_name_field = $key . '_field_name';
$field_name = $this->fieldPrefix . $values[$machine_name_field];
$field_id = $field_info['entity_type'] . '.' . $field_name;
// Check for existing fields.
if (FieldStorageConfig::load($field_id) != NULL) {
$form_state
->setErrorByName($machine_name_field, $this
->t('The machine-readable name is already in use. It must be unique.'));
}
}
else {
$machine_name_field = $key;
$field_id = $field_info['entity_type'] . '.' . $value;
}
// Check for duplicates in new field names.
if (isset($field_names[$field_id])) {
$msg = $this
->t('A field name can not be used more than once in the same group.');
$form_state
->setErrorByName($field_names[$field_id], $msg);
$form_state
->setErrorByName($machine_name_field, $msg);
}
else {
$field_names[$field_id] = $machine_name_field;
}
}
}