Issue #2939107 by plach, Wim Leers: Follow-up for #2924724: Clean up the node revision translation revert logic to leverage the new API
parent
725641cf87
commit
6538805525
|
@ -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 @@ class NodeRevisionRevertTranslationForm extends NodeRevisionRevertForm {
|
|||
* {@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 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
$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(
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue