You are here

public function MergeTranslationsForm::submitForm in Merge translations 8

SubmitForm.

Parameters

array $form: Form.

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

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

Overrides FormInterface::submitForm

File

src/Form/MergeTranslationsForm.php, line 251

Class

MergeTranslationsForm
The merge translation form.

Namespace

Drupal\merge_translations\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $translations = $form_state
    ->getValue('node_translations');
  $action = $form_state
    ->getValue('node_source_action');
  foreach ($translations as $langcode => $source) {
    if (empty($source['node_source']) || ($entity = $this->entityTypeManager
      ->getStorage(self::ENTITYTYPE)
      ->load($source['node_source'])) === NULL) {
      continue;
    }

    // Add translation.
    $this
      ->mergeTranslations($entity, $langcode);
    if (self::ACTION_REMOVE === $action) {
      $this
        ->removeNode($entity);
    }
  }
  $this->node
    ->save();
}