/** * {@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); } }
/** * Overrides Drupal\Core\Entity\EntityForm::save(). */ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); // Everything below this line is only invoked if the 'Submit to provider' // button was clicked. if (isset($form['actions']['submit']) && $form_state->getTriggeringElement()['#value'] == $form['actions']['submit']['#value']) { // Delete conflicting items. if ($existing_items_ids = $form_state->get('existing_item_ids')) { $storage = \Drupal::entityTypeManager()->getStorage('tmgmt_job_item'); $storage->delete($storage->loadMultiple($existing_items_ids)); $num_of_items = count($existing_items_ids); drupal_set_message(\Drupal::translation()->formatPlural($num_of_items, '1 conflicting item has been dropped.', '@count conflicting items have been dropped.'), 'warning'); } if (!tmgmt_job_request_translation($this->entity)) { // Don't redirect the user if the translation request failed but retain // existing destination parameters so we can redirect once the request // finished successfully. unset($_GET['destination']); } elseif ($redirect = tmgmt_redirect_queue_dequeue()) { // Proceed to the next redirect queue item, if there is one. $form_state->setRedirectUrl(Url::fromUri('base:' . $redirect)); } elseif ($destination = tmgmt_redirect_queue_destination()) { // Proceed to the defined destination if there is one. $form_state->setRedirectUrl(Url::fromUri('base:' . $destination)); } else { // Per default we want to redirect the user to the overview. $form_state->setRedirect('view.tmgmt_job_overview.page_1'); } } else { // Per default we want to redirect the user to the overview. $form_state->setRedirect('view.tmgmt_job_overview.page_1'); } }