Problem/Motivation

Recently I found similar bug to this one #2325463: Destination URL breaks preview,

Stepts to reproduce:
- Make some CT translatable, add a couple languages, add some node and translate it into other language.
- Then when you're, let's say, on /af/node/1/translations/add/en/af, add to a url destination param, so your param might looks like
/af/node/1/translations/add/en/af?destination=/node
- Then in the "SOURCE LANGUAGE: ENGLISH" fieldset select another language (Ukrainian), click "Change" button

Expected results:
- I'm staying on the add node translation page
- Url should be changed to the /af/node/1/translations/add/uk/af?destination=/node
- I should see message on the page "Source language set to: Ukrainian"
- After adding a translation, system should redirect me to the url that I set in destination query parameter

Current behavior
- System redirects to the /node page and all my inputs are lost
- I see message on the page "Source language set to: Ukrainian"

Proposed resolution

  • Set destination query to the form state redirect

Remaining tasks

  • Write a CR?
  • Review patch and commit it

User interface changes

  • None

API changes

  • None

Data model changes

  • None

Release notes snippet

Comments

vlad.dancer created an issue. See original summary.

vlad.dancer’s picture

Status: Active » Needs review
StatusFileSize
new4.02 KB
vlad.dancer’s picture

Here is added test without fix to prove the problem.

vlad.dancer’s picture

Issue summary: View changes

Update issue description.

Status: Needs review » Needs work
vlad.dancer’s picture

Status: Needs work » Needs review
StatusFileSize
new6.78 KB

Ok, here is a combined patch - test + fix.

Status: Needs review » Needs work
vlad.dancer’s picture

Status: Needs work » Needs review
StatusFileSize
new6.8 KB

Add base url.

Status: Needs review » Needs work

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

matsbla’s picture

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

matsbla’s picture

StatusFileSize
new6.94 KB
matsbla’s picture

Version: 8.9.x-dev » 9.1.x-dev
matsbla’s picture

StatusFileSize
new2.83 KB
matsbla’s picture

Status: Needs work » Needs review
Issue tags: +Bug Smash Initiative
jungle’s picture

Status: Needs review » Needs work

Thanks, @matsbla!

  1. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -116,8 +122,10 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E
    +   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
    +   *   The request stack.
    ...
    -  public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, MessengerInterface $messenger, DateFormatterInterface $date_formatter, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository) {
    +  public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, MessengerInterface $messenger, DateFormatterInterface $date_formatter, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository, RequestStack $request_stack) {
    

    Needs a CR? Make it optional for BC.

    public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, MessengerInterface $messenger, DateFormatterInterface $date_formatter, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository, RequestStack $request_stack = NULL) {
       if(request_stack === NULL) {
         $request_stack = \Drupal::service('request_stack');
       }
    
    
  2. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php
    @@ -117,6 +118,65 @@ public function testLanguageChange() {
    +   * Test changing the source language with destination parameter.
    

    Start with a verb "Test" -> "Tests"

  3. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php
    @@ -117,6 +118,65 @@ public function testLanguageChange() {
    +    $this->drupalPostForm(NULL, [], t('Save (this translation)'));
    ...
    +    $this->drupalPostForm(NULL, $edit, t('Change'), $add_translation_route['options']);
    ...
    +    $this->drupalPostForm(NULL, $edit, t('Save (this translation)'), $add_translation_route['options']);
    

    t() calls should be avoided in tests where possible.

jungle’s picture

Issue summary: View changes

Applying IS template

matsbla’s picture

StatusFileSize
new3.98 KB
new7.48 KB
matsbla’s picture

Issue summary: View changes
matsbla’s picture

Issue summary: View changes
Issue tags: +Needs change record
matsbla’s picture

Status: Needs work » Needs review

Not sure if CR is needed as the new construct parameter is optional, doesn't look like CR was created other places where new optional parameters where introduced. Put back to NR to get feedback from a core committer.

matsbla’s picture

@jungle
Thanks for the review!

jungle’s picture

  1. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -127,6 +135,10 @@ public function __construct(EntityTypeInterface $entity_type, LanguageManagerInt
         $this->dateFormatter = $date_formatter;
    +    if ($request_stack === NULL) {
    +     $request_stack = \Drupal::service('request_stack');
    +   }
    +    $this->requestStack = $request_stack;
    

    Wrong indentation. the } line.

  2. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -99,6 +100,11 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E
    +   * @var \Symfony\Component\HttpFoundation\RequestStack
    +   */
    

    Missing the summary/comment.

      /**
       * The request stack.
       *
       * @var \Symfony\Component\HttpFoundation\RequestStack
       */
    
  3. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -736,15 +749,23 @@ public function entityFormSubmit($form, FormStateInterface $form_state) {
    +    $entity      = $form_object->getEntity();
    +    $source      = $form_state->getValue(['source_langcode', 'source']);
    +    $query       = $this->requestStack->getCurrentRequest()->query;
    +    $options     = [];
    

    Prefer removing extra whitespaces before =, but your way is allowed by coding standard.

Otherwise, besides the CR, it's good to me. Thanks!

Note: attaching a test-only patch would be better.

jungle’s picture

Status: Needs review » Needs work
matsbla’s picture

StatusFileSize
new7.52 KB
new3.27 KB
new897 bytes

Thank you!

matsbla’s picture

StatusFileSize
new7.52 KB
new3.27 KB
new721 bytes
matsbla’s picture

Status: Needs work » Needs review

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

larowlan’s picture

Status: Needs review » Needs work

Looking good, couple of observations/suggestions

  1. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -127,6 +137,10 @@ public function __construct(EntityTypeInterface $entity_type, LanguageManagerInt
    +      $request_stack = \Drupal::service('request_stack');
    

    This will need a trigger_error for BC sake to notify of the deprecation for D10

  2. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php
    @@ -117,6 +118,65 @@ public function testLanguageChange() {
    +    $this->assertTrue(strpos($this->getUrl(), $add_translation_href) !== FALSE, 'Correct destination query arguments are found');
    

    We could use assertStringContainsString here instead and then the $message isn't needed

spokje’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
StatusFileSize
new7.16 KB
new2.6 KB

1. Added draft CR: #3189305: \Drupal\content_translation\ContentTranslationHandler constructor adds $request_stack argument.
2. Reroll against 9.2.x including fixing deprecations
3. Addressed both points in #32 in attached patch.

gauravvvv’s picture

StatusFileSize
new29.32 KB

Patch applied cleanly. Moving to RTBC.

gauravvvv’s picture

Status: Needs review » Reviewed & tested by the community
gauravvvv’s picture

gauravvvv’s picture

Status: Reviewed & tested by the community » Needs review

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ranjith_kumar_k_u’s picture

StatusFileSize
new7.23 KB

Rerolled #33.

gauravvvv’s picture

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

CI Failure.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.