Overrides Drupal\Core\Entity\EntityForm::form().
Overrides JobForm::form
public function form(array $form, FormStateInterface $form_state) {
$job = $this->entity;
// Handle source language.
$available['source_language'] = tmgmt_available_languages();
// Handle target language.
$selected = $job
->getSourceLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED ? $job
->getSourceLangcode() : array_keys(tmgmt_available_languages())[0];
$available['target_language'] = tmgmt_available_languages([
$selected,
]);
$this->entity
->set('job_type', Job::TYPE_CONTINUOUS);
$form = parent::form($form, $form_state);
// Set the title of the page to the label and the current state of the job.
$form['#title'] = t('@title', array(
'@title' => 'New Continuous Job',
));
$form['label']['widget'][0]['value']['#description'] = t('You need to provide a label for this job in order to identify it later on.');
$form['label']['widget'][0]['value']['#required'] = TRUE;
$form['info']['source_language'] = array(
'#title' => t('Source language'),
'#type' => 'select',
'#options' => $available['source_language'],
'#default_value' => $job
->getSourceLangcode(),
'#required' => TRUE,
'#prefix' => '<div id="tmgmt-ui-source-language" class="tmgmt-ui-source-language tmgmt-ui-info-item">',
'#suffix' => '</div>',
'#ajax' => array(
'callback' => array(
$this,
'ajaxSourceLanguageSelect',
),
'wrapper' => 'tmgmt-ui-target-language',
'event' => 'change',
),
);
$form['info']['target_language'] = array(
'#title' => t('Target language'),
'#type' => 'select',
'#options' => $available['target_language'],
'#default_value' => $job
->getTargetLangcode(),
'#required' => TRUE,
'#prefix' => '<div id="tmgmt-ui-target-language" class="tmgmt-ui-target-language tmgmt-ui-info-item">',
'#suffix' => '</div>',
'#ajax' => array(
'callback' => array(
$this,
'ajaxLanguageSelect',
),
'wrapper' => 'tmgmt-ui-target-language',
),
'#validated' => TRUE,
);
return $form;
}