public function CustomServicesAddForm::validateForm in Shorten URLs 8
Same name and namespace in other branches
- 8.2 modules/shorten_cs/src/Form/CustomServicesAddForm.php \Drupal\shorten_cs\Form\CustomServicesAddForm::validateForm()
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
- modules/
shorten_cs/ src/ Form/ CustomServicesAddForm.php, line 100
Class
- CustomServicesAddForm
- Settings form.
Namespace
Drupal\shorten_cs\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$v = $form_state
->getValues();
if (($v['type'] == 'xml' || $v['type'] == 'json') && empty($v['tag'])) {
$form_state
->setErrorByName('type', t('An XML tag or JSON key is required for services with a response type of XML or JSON.'));
}
$exists = db_query("SELECT COUNT(sid) FROM {shorten_cs} WHERE name = :name", array(
':name' => $v['name'],
))
->fetchField();
if ($exists > 0) {
$form_state
->setErrorByName('name', t('A service with that name already exists.'));
}
else {
$all_services = \Drupal::moduleHandler()
->invokeAll('shorten_service');
$all_services['none'] = t('None');
foreach ($all_services as $key => $value) {
if ($key == $v['name']) {
$form_state
->setErrorByName('name', t('A service with that name already exists.'));
break;
}
}
}
}