/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); /** @var JobItem $item */ $item = $this->buildEntity($form, $form_state); // First invoke the validation method on the source controller. $source_ui = $this->sourceManager->createUIInstance($item->getPlugin()); $source_ui->reviewFormValidate($form, $form_state, $item); // Invoke the validation method on the translator controller (if available). if ($item->hasTranslator()) { $translator_ui = $this->translatorManager->createUIInstance($item->getTranslator()->getPluginId()); $translator_ui->reviewFormValidate($form, $form_state, $item); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { /** @var \Drupal\tmgmt\JobInterface $job */ $job = parent::validateForm($form, $form_state); if ($job->hasTranslator()) { $translator = $job->getTranslator(); // Check translator availability. $available_status = $translator->checkAvailable(); $translatable_status = $translator->checkTranslatable($job); if (!$available_status->getSuccess()) { $form_state->setErrorByName('translator', $available_status->getReason()); } elseif (!$translatable_status->getSuccess()) { $form_state->setErrorByName('translator', $translatable_status->getReason()); } } if (!$job->isContinuous() && isset($form['actions']['submit']) && $form_state->getTriggeringElement()['#value'] == $form['actions']['submit']['#value']) { $existing_items_ids = $job->getConflictingItemIds(); $form_state->set('existing_item_ids', $existing_items_ids); // If the amount of existing items is the same as the total job item count // then the job can not be submitted. if (count($job->getItems()) == count($existing_items_ids)) { $form_state->setErrorByName('target_language', $this->t('All job items are conflicting, the job can not be submitted.')); } } }