Route "_title_arguments" computation may be incorrect

Created on 13 September 2019, over 5 years ago
Updated 31 January 2023, almost 2 years ago

API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Controlle...

The code for getting the arguments for the route in TitleResolver.php file in getTitle() is as follows:

      $args = [];
      if (($raw_parameters = $request->attributes->get('_raw_variables'))) {
        foreach ($raw_parameters->all() as $key => $value) {
          $args['@' . $key] = $value;
          $args['%' . $key] = $value;
        }
      }
      if ($title_arguments = $route->getDefault('_title_arguments')) {
        $args = array_merge($args, (array) $title_arguments);
      }

Here '_title_arguments' are the arguments specified in the routing file, which IMO, should be the default value in case "_raw_variables" are not there.

So IMO, the array_merge() should be:
array_merge((array) $title_arguments, $args);

šŸ› Bug report
Status

Needs work

Version

10.1 āœØ

Component
RoutingĀ  ā†’

Last updated about 6 hours ago

Created by

šŸ‡®šŸ‡³India Vivek Panicker Kolkata

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • šŸ‡ŗšŸ‡øUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request ā†’ as a guide.

    This will need a test case to show the issue.

    Did not test for the issue.

  • šŸ‡¬šŸ‡§United Kingdom nlisgo

    This seems to be clearly described. Tagged as Needs tests and it should be easy to add a test.

  • Assigned to nlisgo
  • šŸ‡¬šŸ‡§United Kingdom nlisgo

    Will work on a fix with test.

  • Pipeline finished with Success
    7 months ago
    Total: 844s
    #211778
  • Status changed to Needs review 7 months ago
  • šŸ‡¬šŸ‡§United Kingdom nlisgo
  • šŸ‡¬šŸ‡§United Kingdom nlisgo
  • Status changed to Needs work 7 months ago
  • šŸ‡ŗšŸ‡øUnited States smustgrave

    Can issue summary be updated using the issue template please

  • Issue was unassigned.
  • šŸ‡¬šŸ‡§United Kingdom nlisgo
  • šŸ‡®šŸ‡³India shalini_jha

    I have tested MR 8584, and after these changes, when the parameter is available in the URL, the getTitle method returns the value from the URL parameter instead of the static value from the routing. Additionally, I have updated the issue summary.
    Moving this to NR, Kindly review.

  • šŸ‡®šŸ‡³India Vivek Panicker Kolkata

    Thanks @shalini.

    @smustgrave the issue summary is fixed and MR is tested now.

  • šŸ‡ŗšŸ‡øUnited States smustgrave

    This issue needs a rebase 488 commits behind, the pipeline can't be reliable at that point.

  • Pipeline finished with Failed
    3 months ago
    Total: 51538s
    #323179
  • Pipeline finished with Success
    3 months ago
    Total: 534s
    #323710
  • šŸ‡®šŸ‡³India shalini_jha

    I have rebased this MR, and the pipeline has passed successfully. Moving it to 'Needs Review'.
    Kindly review.

  • šŸ‡ŗšŸ‡øUnited States smustgrave

    So see that 2 tests have been added but when the test-only feature is ran only testStaticTitleWithDefaultArgumentsOverridden is failing.

  • šŸ‡®šŸ‡³India shalini_jha

    I have verified that the testStaticTitleWithDefaultArguments method checks the default behaviour of using static titles with preset arguments without testing dynamic overrides, which is why it does not fail. The issue is specifically addressed in testStaticTitleWithDefaultArgumentsOverridden, where dynamic URL parameters should replace default values but are not being applied correctly.

    Please let me know if we should remove the method that tests the default functionality. Moving this to "Needs Review."

  • šŸ‡ŗšŸ‡øUnited States smustgrave

    Lets consolidate them. The code seems very similar so probably overlaps.

  • Pipeline finished with Success
    3 months ago
    Total: 475s
    #336288
  • Pipeline finished with Failed
    3 months ago
    Total: 82s
    #336302
  • šŸ‡®šŸ‡³India shalini_jha

    I have consolidated both test methods into a single one and tested it. It is working as expected. Moving this to NR for review. Kindly review.

    Failing test :

    PHPUnit 10.5.38 by Sebastian Bergmann and contributors.
    
    Runtime:       PHP 8.3.12
    Configuration: /var/www/html/core/phpunit.xml.dist
    
    F                                                                   1 / 1 (100%)
    
    Time: 00:04.851, Memory: 186.00 MB
    
    There was 1 failure:
    
    1) Drupal\Tests\Core\Controller\TitleResolverTest::testStaticTitleWithArguments
    Failed asserting that two objects are equal.
    --- Expected
    +++ Actual
    @@ @@
     Drupal\Core\StringTranslation\TranslatableMarkup Object (
         'string' => 'static title @test @test2'
         'arguments' => Array (
    -        '@test' => 'override value'
    +        '@test' => 'value'
             '%test' => 'override value'
             '@test2' => 'value2'
         )
    
    /var/www/html/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php:153
    
  • Pipeline finished with Success
    3 months ago
    Total: 8215s
    #336319
  • šŸ‡ŗšŸ‡øUnited States smustgrave

    Feedback appears to be addressed.

  • šŸ‡³šŸ‡æNew Zealand quietone

    I read the IS, comments and the MR. This looks in order. I don't know much about routing so did some investigation.

    The code being changed was added in 2014 in [ #2120235] but it doesn't address the purpose of the _title_arguments. The Structure of routes ā†’ states

    _title_arguments: Additional arguments for the title text passed along to t().

    If that is true then I wonder if this is working as designed. If it is not this needs a title update.

  • šŸ‡¬šŸ‡§United Kingdom alexpott šŸ‡ŖšŸ‡ŗšŸŒ

    This is a change in behaviour. Potentially someone might be relying on the ability of _title_arguments to override the arguments based on the routes raw parameters. That means I think we need a change record. Unfortunately there is no documentation in core about _title_arguments as ideally the behaviour should be documented there. The change being made here however is inline with the documentation linked to from #32 as this now means that _title_arguments can only define additional arguments and values and not override stuff coming from the route.

  • Pipeline finished with Success
    17 days ago
    Total: 450s
    #391623
  • Pipeline finished with Success
    17 days ago
    Total: 318s
    #391627
  • šŸ‡®šŸ‡³India shalini_jha

    Thank you for the review and feedback. Based on the suggestions provided, I tested the functionality after implementing the recommended changes, and it is now working as expected. There is no need for an array_merge after retrieving the arguments from _raw_variables. I also re-ran the tests, and they are passing successfully.

    I have also drafted a CR ā†’ based on the work done and provided an explanation of the changes made. However, Iā€™m unsure if anything else needs to be added. I kindly request you to review it and share your feedback. Thank you!

  • šŸ‡ŗšŸ‡øUnited States smustgrave

    Think the title of the MR probably makes more sense.

    CR seems well detailed

    Believe all feedback has been addressed.

  • šŸ‡¬šŸ‡§United Kingdom alexpott šŸ‡ŖšŸ‡ŗšŸŒ

    As this is a subtle behaviour change I'm going to only put this in 11.2.x to give people a chance to notice this change.

    Committed 0c9b4fc and pushed to 11.x. Thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024