public function WebformHandlerFormBase::validateMachineName in Webform 6.x
Validates the machine name for a webform handler instance.
This method verifies the uniqueness of the machine name and updates the machine name with a count suffix if another handler with the same machine name already exists.
See also
\Drupal\Core\Render\Element\MachineName::validateMachineName()
File
- src/
Form/ WebformHandlerFormBase.php, line 344
Class
- WebformHandlerFormBase
- Provides a base webform for webform handlers.
Namespace
Drupal\webform\FormCode
public function validateMachineName(&$element, FormStateInterface $form_state, &$complete_form) {
// If the machine name matches the default machine name, it does not need to
// be validated (i.e. during handler edit form save).
if (isset($element['#default_value']) && $element['#default_value'] === $element['#value']) {
return;
}
$count = 1;
$machine_name = $element['#value'];
$instance_ids = $this->webform
->getHandlers()
->getInstanceIds();
while (isset($instance_ids[$machine_name])) {
$machine_name = $element['#value'] . '_' . $count++;
}
$element['#value'] = $machine_name;
$form_state
->setValueForElement($element, $machine_name);
}