You are here

protected function SupportTicketRevisionRevertForm::prepareRevertedRevision in Support Ticketing System 8

Prepares a revision to be reverted.

Parameters

\Drupal\support_ticket\SupportTicketInterface $revision: The revision to be reverted.

Return value

\Drupal\support_ticket\SupportTicketInterface The prepared revision ready to be stored.

1 call to SupportTicketRevisionRevertForm::prepareRevertedRevision()
SupportTicketRevisionRevertForm::submitForm in modules/support_ticket/src/Form/SupportTicketRevisionRevertForm.php
Form submission handler.

File

modules/support_ticket/src/Form/SupportTicketRevisionRevertForm.php, line 130
Contains \Drupal\support_ticket\Form\SupportTicketRevisionRevertForm.

Class

SupportTicketRevisionRevertForm
Provides a form for reverting a support ticket revision.

Namespace

Drupal\support_ticket\Form

Code

protected function prepareRevertedRevision(SupportTicketInterface $revision) {

  /** @var \Drupal\support_ticket\SupportTicketInterface $default_revision */
  $default_revision = $this->supportTicketStorage
    ->load($revision
    ->id());

  // If the entity is translated, make sure only translations affected by the
  // specified revision are reverted.
  $languages = $default_revision
    ->getTranslationLanguages();
  if (count($languages) > 1) {
    foreach ($languages as $langcode => $language) {
      if ($revision
        ->hasTranslation($langcode) && !$revision
        ->getTranslation($langcode)
        ->isRevisionTranslationAffected()) {
        $revision_translation = $revision
          ->getTranslation($langcode);
        $default_translation = $default_revision
          ->getTranslation($langcode);
        foreach ($default_revision
          ->getFieldDefinitions() as $field_name => $definition) {
          if ($definition
            ->isTranslatable()) {
            $revision_translation
              ->set($field_name, $default_translation
              ->get($field_name)
              ->getValue());
          }
        }
      }
    }
  }
  $revision
    ->setNewRevision();
  $revision
    ->isDefaultRevision(TRUE);
  return $revision;
}