You are here

public function MergeTranslationsForm::validateForm in Merge translations 8

Validate the submitted values.

Parameters

array $form: Form.

\Drupal\Core\Form\FormStateInterface $form_state: FormState.

Overrides FormBase::validateForm

File

src/Form/MergeTranslationsForm.php, line 278

Class

MergeTranslationsForm
The merge translation form.

Namespace

Drupal\merge_translations\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $translations = $form_state
    ->getValue('node_translations');
  foreach ($translations as $langcode => $source) {
    if (empty($source['node_source'])) {
      continue;
    }
    if ($this->node
      ->id() === $source['node_source']) {
      $form_state
        ->setErrorByName("node_translations][{$langcode}", $this
        ->t('Translation source and target can not be the same'));
    }
  }
  parent::validateForm($form, $form_state);
}