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 3 days 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
    6 months ago
    Total: 844s
    #211778
  • Status changed to Needs review 6 months ago
  • 🇬🇧United Kingdom nlisgo
  • 🇬🇧United Kingdom nlisgo
  • Status changed to Needs work 6 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
    about 2 months ago
    Total: 51538s
    #323179
  • Pipeline finished with Success
    about 2 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
    about 1 month ago
    Total: 475s
    #336288
  • Pipeline finished with Failed
    about 1 month 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
    about 1 month 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.

Production build 0.71.5 2024