You are here

protected function SitewideAlertRevisionRevertTranslationForm::prepareRevertedRevision in Sitewide Alert 8

Prepares a revision to be reverted.

Parameters

\Drupal\sitewide_alert\Entity\SitewideAlertInterface $revision: The revision to be reverted.

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

Return value

\Drupal\sitewide_alert\Entity\SitewideAlertInterface The prepared revision ready to be stored.

Overrides SitewideAlertRevisionRevertForm::prepareRevertedRevision

File

src/Form/SitewideAlertRevisionRevertTranslationForm.php, line 96

Class

SitewideAlertRevisionRevertTranslationForm
Provides a form for reverting a Sitewide Alert revision for a single trans.

Namespace

Drupal\sitewide_alert\Form

Code

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

  /** @var \Drupal\sitewide_alert\Entity\SitewideAlertInterface $default_revision */
  $latest_revision = $this->SitewideAlertStorage
    ->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;
}