Commit 65388055 authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2939107 by plach, Wim Leers: Follow-up for #2924724: Clean up the node...

Issue #2939107 by plach, Wim Leers: Follow-up for #2924724: Clean up the node revision translation revert logic to leverage the new API
parent 725641cf
......@@ -28,7 +28,7 @@ class NodeRevisionRevertForm extends ConfirmFormBase {
/**
* The node storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
* @var \Drupal\node\NodeStorageInterface
*/
protected $nodeStorage;
......
......@@ -106,24 +106,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $node_rev
* {@inheritdoc}
*/
protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) {
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
/** @var \Drupal\node\NodeInterface $default_revision */
$latest_revision = $this->nodeStorage->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);
return $latest_revision_translation;
$revert_untranslated_fields = (bool) $form_state->getValue('revert_untranslated_fields');
$translation = $revision->getTranslation($this->langcode);
return $this->nodeStorage->createRevision($translation, TRUE, $revert_untranslated_fields);
}
}
......@@ -64,6 +64,9 @@ protected function setUp() {
$field = FieldConfig::create($field_definition);
$field->save();
// Enable translation for page nodes.
\Drupal::service('content_translation.manager')->setEnabled('node', 'page', TRUE);
// Create and log in user.
$web_user = $this->drupalCreateUser(
[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment