protected function OpignoAnswerRevisionRevertTranslationForm::prepareRevertedRevision in Opigno module 8
Same name and namespace in other branches
- 3.x src/Form/OpignoAnswerRevisionRevertTranslationForm.php \Drupal\opigno_module\Form\OpignoAnswerRevisionRevertTranslationForm::prepareRevertedRevision()
Prepares a revision to be reverted.
Parameters
\Drupal\opigno_module\Entity\OpignoAnswerInterface $revision: The revision to be reverted.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
\Drupal\opigno_module\Entity\OpignoAnswerInterface The prepared revision ready to be stored.
Overrides OpignoAnswerRevisionRevertForm::prepareRevertedRevision
File
- src/
Form/ OpignoAnswerRevisionRevertTranslationForm.php, line 93
Class
- OpignoAnswerRevisionRevertTranslationForm
- Provides a form for reverting a Answer revision for a single translation.
Namespace
Drupal\opigno_module\FormCode
protected function prepareRevertedRevision(OpignoAnswerInterface $revision, FormStateInterface $form_state) {
$revert_untranslated_fields = $form_state
->getValue('revert_untranslated_fields');
/** @var \Drupal\opigno_module\Entity\OpignoAnswerInterface $default_revision */
$latest_revision = $this->OpignoAnswerStorage
->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;
}