Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
With Drupal 8.0.3,
drush php-eval 'print_r(\Drupal::urlGenerator()->generate("entity.node.content_translation_overview",["node" => 1], \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL) . PHP_EOL);'
Outputs an absolute url:
http://default/node/1/translations
With Drupal 8.1.x, the same command outputs a relative url:
/node/1/translations
See https://github.com/symfony/routing/commit/502cac1e711e708044e23a38ef3a45... for the root cause.
Proposed resolution
Change the logic in our \Drupal\Core\Routing\UrlGenerator::generateFromRoute() and add explicit tests that looks we are lacking.
Remaining tasks
Provide a first patch
User interface changes
None.
API changes
Ideally none, we can abstract this Symfony change.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#22 | interdiff-22.txt | 1.84 KB | esclapes |
#22 | unexpected_api_change-2674780-22.patch | 4.06 KB | esclapes |
#19 | interdiff-19.txt | 2.27 KB | esclapes |
#19 | unexpected_api_change-2674780-19.patch | 4.77 KB | esclapes |
#18 | interdiff.txt | 2.55 KB | esclapes |
Comments
Comment #2
penyaskitoInitial patch.
Comment #3
dawehnerLet's ensure we have test coverage for the different available types ...
Comment #4
catchTagging for release notes in case it's not fixed in time.
I'm assuming this breaks install in subdirectories, so bumping to major for that reason. If I've got that wrong and it's just a correct absolute vs. relative url then we could bump back to normal though.
Comment #6
dawehnerIn general its great that we got this committed so people find the issue.
Comment #7
esclapes CreditAttribution: esclapes as a volunteer commentedLooking at the root issue, there is a missmatch between the Synfony
UrlGeneratorInterface->generate()
which expects$refernceType
to be a constant and our implemenentation atUrlGenerator->generate()
that even renames$refernceType
toabsolute
and uses a boolean.A have added two tests for absolute and relative URL generation (some part of them might be redundant as I am not familiar with the bubbling thing) and moved the fix from #2 to the generate method.
Comment #8
esclapes CreditAttribution: esclapes as a volunteer commentedThis is the same patch, but fixing the interface missmatch.
EDIT with more info.
instead of
I have only run the tests with
./vendor/bin/phpunit --bootstrap ./core/tests/bootstrap.php core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
, and they pass with both patches.Comment #11
esclapes CreditAttribution: esclapes as a volunteer commentedNot sure why the new tests are failing. The messages in QA are these:
Any idea? Test pass in my VM
Comment #12
catchDebugged the test locally. MetadataBubblingUrlGenerator needed exactly the same change as UrlGenerator. The test methods you added passed for that test, but this is a different test that inherits from the one you updated which is why it confusingly looks like the test is passing when you run just that one.
Comment #13
dawehnerMh, so this fixes the case of ABSOLUTE_URL/ABSOLUTE_PATH but should we not also deal with the case of it being a string, see
Given that do we also expand the test coverage to use the other 2 reference types (relative path and network path)?
Comment #14
catchHmm well we only ever supported ABSOLUTE_URL/ABSOLUTE_PATH with the previous method signature via the $absolute = FALSE bool, so no-one should ever have been passing a string in there. Since this is just a bc layer I don't think we should support things we didn't previously by it.
Don't know about RELATIVE_PATH and NETWORK_PATH - again we didn't previously support them, I guess we could add coverage to ensure that now they are supported they actually work though.
Comment #15
dawehnerOkay that is a fair point. Can we open a follow up, given that we implement that interface, which documents it exists. People might expand it works
Comment #16
catchOpened #2676288: Symfony 2.8 supports RELATIVE_URL and NETWORK_URL in the URL generator - add test coverage.
I'm not sure if coding standards allow it, but it would be good to document the @deprecated parameters for $reference_type/$absolute here.
Comment #17
dawehnerIMHO we should also keep the snake case of the interface, especially because otherwise API module might have a problem with scanning it.
Comment #18
esclapes CreditAttribution: esclapes as a volunteer commentedIncludes suggestioins from #17 and #16:
Indeed, the current generated docs do not detect the interface inheritance for the
generate
method.There seems to be no way to deprecate parameters in docblock so I used an
if/else
block and included atrigger_error
. It makes for a bigger patch but it makes sense to rise a notice. I have found a few usages oftrigger_error
in core so I guess it is fine according to CS.Comment #19
esclapes CreditAttribution: esclapes as a volunteer commentedJust realized that
trigger_error
makes phpunit fail. I see that other core components use the@trigger_error
and passes with phpunit. Attached.Comment #21
catchI personally wouldn't use trigger_error() yet, this is Symfony's deprecation not ours yet - we can just write that the bool is deprecated in the @param docs for now. I'd like to start using E_USER_DEPRECATED a lot more in 8.2.x though so good for a follow-up. See #2575081: [policy, no patch] Use E_USER_DEPRECATED in Drupal 8 minor releases for more discussion of that.
Comment #22
esclapes CreditAttribution: esclapes as a volunteer commentedOK, this patch is based on #12 and renames the argument to
$referenceType
in order to match the interface signature.As per #1994890: Allow {@inheritdoc} and additional documentation there seems to be no way to add extra information to
@inheritdoc
so I did nothing regarding the deprecation info.Comment #23
dawehnerCan we add a follow up to actually support the other reference types as well, both in generate() and in generateFromRoute() ? For now this patch resolves the problem with the BC break.
IMHO its fine to stick with the current situation in terms of the documentation. generate() is not recommended API anyway.
Comment #24
penyaskito@dawehner: wasn't #2676288: Symfony 2.8 supports RELATIVE_URL and NETWORK_URL in the URL generator - add test coverage created by catch for that?
Comment #25
dawehnerYou are right!
Comment #26
catchComment #27
alexpottCommitted c4145ed and pushed to 8.1.x and 8.2.x. Thanks!