You are here

protected function EasyEmailRevisionRevertTranslationForm::prepareRevertedRevision in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x src/Form/EasyEmailRevisionRevertTranslationForm.php \Drupal\easy_email\Form\EasyEmailRevisionRevertTranslationForm::prepareRevertedRevision()

Prepares a revision to be reverted.

Parameters

\Drupal\easy_email\Entity\EasyEmailInterface $revision: The revision to be reverted.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\easy_email\Entity\EasyEmailInterface The prepared revision ready to be stored.

Overrides EasyEmailRevisionRevertForm::prepareRevertedRevision

File

src/Form/EasyEmailRevisionRevertTranslationForm.php, line 93

Class

EasyEmailRevisionRevertTranslationForm
Provides a form for reverting a Email revision for a single translation.

Namespace

Drupal\easy_email\Form

Code

protected function prepareRevertedRevision(EasyEmailInterface $revision, FormStateInterface $form_state) {
  $revert_untranslated_fields = $form_state
    ->getValue('revert_untranslated_fields');

  /** @var \Drupal\easy_email\Entity\EasyEmailInterface $default_revision */
  $latest_revision = $this->EasyEmailStorage
    ->load($revision
    ->id());
  $latest_revision_translation = $latest_revision
    ->getTranslation($this->langcode);
  $revision_translation = $revision
    ->getTranslation($this->langcode);
  foreach ($latest_revision_translation
    ->getFieldDefinitions() as $field_name => $definition) {
    if ($definition
      ->isTranslatable() || $revert_untranslated_fields) {
      $latest_revision_translation
        ->set($field_name, $revision_translation
        ->get($field_name)
        ->getValue());
    }
  }
  $latest_revision_translation
    ->setNewRevision();
  $latest_revision_translation
    ->isDefaultRevision(TRUE);
  $revision
    ->setRevisionCreationTime(\Drupal::time()
    ->getRequestTime());
  return $latest_revision_translation;
}