You are here

protected function FlaggingCollectionRevisionRevertTranslationForm::prepareRevertedRevision in Flag Lists 8

Same name and namespace in other branches
  1. 4.0.x src/Form/FlaggingCollectionRevisionRevertTranslationForm.php \Drupal\flag_lists\Form\FlaggingCollectionRevisionRevertTranslationForm::prepareRevertedRevision()

Prepares a revision to be reverted.

Parameters

\Drupal\flag_lists\Entity\FlaggingCollectionInterface $revision: The revision to be reverted.

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

Return value

\Drupal\flag_lists\Entity\FlaggingCollectionInterface The prepared revision ready to be stored.

Overrides FlaggingCollectionRevisionRevertForm::prepareRevertedRevision

File

src/Form/FlaggingCollectionRevisionRevertTranslationForm.php, line 95

Class

FlaggingCollectionRevisionRevertTranslationForm
Provides a form for reverting a Flagging collection revision.

Namespace

Drupal\flag_lists\Form

Code

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

  /** @var \Drupal\flag_lists\Entity\FlaggingCollectionInterface $default_revision */
  $latest_revision = $this->FlaggingCollectionStorage
    ->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(REQUEST_TIME);
  return $latest_revision_translation;
}