function JobForm::addSuggestionsSubmit in Translation Management Tool 8
Adds selected suggestions to the job.
File
- src/
Form/ JobForm.php, line 773
Class
- JobForm
- Form controller for the job edit forms.
Namespace
Drupal\tmgmt\FormCode
function addSuggestionsSubmit(array $form, FormStateInterface $form_state) {
// Save all selected suggestion items.
if (is_array($form_state
->getValue('suggestions_table'))) {
$job = $form_state
->getFormObject()
->getEntity();
foreach ($form_state
->getValue('suggestions_table') as $id) {
$key = (int) $id - 1;
// Because in the tableselect we need an idx > 0.
if (isset($form_state
->get('tmgmt_suggestions')[$key]['job_item'])) {
$item = $form_state
->get('tmgmt_suggestions')[$key]['job_item'];
$job
->addExistingItem($item);
}
}
}
// Force a rebuild of the form.
$form_state
->setRebuild();
$form_state
->set('tmgmt_suggestions', NULL);
}