Commit 258f5444 authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2949815 by plach, catch: Flagging translations as outdated in a pending...

Issue #2949815 by plach, catch: Flagging translations as outdated in a pending revision causes multiple translations to be marked as affected
parent ab9c396b
......@@ -61,6 +61,13 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E
*/
protected $manager;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The current user.
*
......@@ -104,6 +111,7 @@ public function __construct(EntityTypeInterface $entity_type, LanguageManagerInt
$this->entityType = $entity_type;
$this->languageManager = $language_manager;
$this->manager = $manager;
$this->entityTypeManager = $entity_manager;
$this->currentUser = $current_user;
$this->fieldStorageDefinitions = $entity_manager->getLastInstalledFieldStorageDefinitions($this->entityTypeId);
$this->messenger = $messenger;
......@@ -445,12 +453,19 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
];
$translate = !$new_translation && $metadata->isOutdated();
if (!$translate) {
$outdated_access = !ContentTranslationManager::isPendingRevisionSupportEnabled($entity->getEntityTypeId(), $entity->bundle());
if (!$outdated_access) {
$form['content_translation']['outdated'] = [
'#markup' => $this->t('Translations cannot be flagged as outdated when content is moderated.'),
];
}
elseif (!$translate) {
$form['content_translation']['retranslate'] = [
'#type' => 'checkbox',
'#title' => t('Flag other translations as outdated'),
'#default_value' => FALSE,
'#description' => t('If you made a significant change, which means the other translations should be updated, you can flag all translations of this content as outdated. This will not change any other property of them, like whether they are published or not.'),
'#access' => $outdated_access,
];
}
else {
......@@ -459,6 +474,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
'#title' => t('This translation needs to be updated'),
'#default_value' => $translate,
'#description' => t('When this option is checked, this translation needs to be updated. Uncheck when the translation is up to date again.'),
'#access' => $outdated_access,
];
$form['content_translation']['#open'] = TRUE;
}
......
<?php
namespace Drupal\Tests\content_translation\Functional;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
/**
* Tests the "Flag as outdated" functionality with revision translations.
*
* @group content_translation
*/
class ContentTranslationOutdatedRevisionTranslationTest extends ContentTranslationPendingRevisionTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->enableContentModeration();
}
/**
* Tests that outdated revision translations work correctly.
*/
public function testFlagAsOutdatedHidden() {
// Create a test node.
$values = [
'title' => 'Test 1.1 EN',
'moderation_state' => 'published',
];
$id = $this->createEntity($values, 'en');
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->storage->load($id);
// Add a published Italian translation.
$add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
$entity->getEntityTypeId() => $id,
'source' => 'en',
'target' => 'it',
],
[
'language' => ConfigurableLanguage::load('it'),
'absolute' => FALSE,
]
);
$this->drupalGet($add_translation_url);
$this->assertFlagWidget();
$edit = [
'title[0][value]' => 'Test 1.2 IT',
'moderation_state[0][state]' => 'published',
];
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
// Add a published French translation.
$add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
$entity->getEntityTypeId() => $id,
'source' => 'en',
'target' => 'fr',
],
[
'language' => ConfigurableLanguage::load('fr'),
'absolute' => FALSE,
]
);
$this->drupalGet($add_translation_url);
$this->assertFlagWidget();
$edit = [
'title[0][value]' => 'Test 1.3 FR',
'moderation_state[0][state]' => 'published',
];
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
// Create an English draft.
$entity = $this->storage->loadUnchanged($id);
$en_edit_url = $this->getEditUrl($entity);
$this->drupalGet($en_edit_url);
$this->assertFlagWidget();
}
/**
* Checks whether the flag widget is displayed.
*/
protected function assertFlagWidget() {
$this->assertSession()->pageTextNotContains('Flag other translations as outdated');
$this->assertSession()->pageTextContains('Translations cannot be flagged as outdated when content is moderated.');
}
}
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\content_translation\Functional;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
......@@ -236,4 +237,24 @@ protected function createEntity($values, $langcode, $bundle_name = NULL) {
return $entity->id();
}
/**
* Returns the edit URL for the specified entity.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity being edited.
*
* @return \Drupal\Core\Url
* The edit URL.
*/
protected function getEditUrl(ContentEntityInterface $entity) {
if ($entity->access('update', $this->loggedInUser)) {
$url = $entity->toUrl('edit-form');
}
else {
$url = $entity->toUrl('drupal:content-translation-edit');
$url->setRouteParameter('language', $entity->language()->getId());
}
return $url;
}
}
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