function tmgmt_smartling_create_job_form_validate in TMGMT Translator Smartling 8.4
Same name and namespace in other branches
- 8.3 tmgmt_smartling.module \tmgmt_smartling_create_job_form_validate()
Validate "Create job" tmgmt_smartling checkout job form part.
Parameters
array $form:
\Drupal\Core\Form\FormStateInterface $form_state:
1 call to tmgmt_smartling_create_job_form_validate()
- tmgmt_smartling_tmgmt_job_edit_form_validate in ./
tmgmt_smartling.module - Validate tmgmt_smartling checkout job form.
File
- ./
tmgmt_smartling.module, line 591 - Contains
Code
function tmgmt_smartling_create_job_form_validate(array &$form, FormStateInterface $form_state) {
$settings = $form_state
->getValue('settings');
$translator = $form_state
->getFormObject()
->getEntity()
->getTranslator();
$translator_plugin = $translator
->getPlugin();
if (empty($settings['create_new_job_tab']['name'])) {
$form_state
->setError($form['translator_wrapper']['settings']['create_new_job_tab']['name'], t('@name field is required.', [
'@name' => t('Job Name'),
]));
}
else {
$response = $translator_plugin
->getApiWrapper($translator
->getSettings())
->listJobs($settings['create_new_job_tab']['name']);
if (!empty($response['items'])) {
foreach ($response['items'] as $item) {
if ($item['jobName'] == $settings['create_new_job_tab']['name']) {
$form_state
->setError($form['translator_wrapper']['settings']['create_new_job_tab']['name'], t('Job with name "@name" already exists. Please choose another job name.', [
'@name' => $settings['create_new_job_tab']['name'],
]));
break;
}
}
}
}
if (!empty($settings['create_new_job_tab']['due_date']) && $settings['create_new_job_tab']['due_date'] instanceof DrupalDateTime && $settings['create_new_job_tab']['due_date']
->getTimeStamp() < time()) {
$form_state
->setError($form['translator_wrapper']['settings']['create_new_job_tab']['due_date'], t('Due date can not be in the past.'));
}
}