Problem/Motivation
#2350835: Mark EntityInterface::getSystemPath() as deprecated deprecated EntityInterface::getSystemPath(), so its use in core should be minimized.
Proposed resolution
Replace as many calls to use routes instead. The methods themselves will not be removed as part of this issue. We still have type of calls left, views link fields: #2404603: Add proper support for Url objects in FieldPluginBase::renderAsLink(), so we can remove EntityInterface::getSystemPath().
The path alias system still works with system paths, and no solution for that is in sight, but those calls have been updated to use urlInfo()->getInternalPath(), which is also deprecated, but less likely to be removed in 8.x.
Remaining tasks
None.
User interface changes
None.
API changes
* Don't use $entity::getSystemPath()
but use $entity::url()/urlInfo()
if possible instead.
Original report by @pwolanin
Follow-up to #2350835: Mark EntityInterface::getSystemPath() as deprecated
EntityInterface::getSystemPath() should be removed after uses are removed.
Comment | File | Size | Author |
---|---|---|---|
#109 | entity-get-system-path-2350837-109-interdiff.txt | 740 bytes | Berdir |
#109 | entity-get-system-path-2350837-109.patch | 95.49 KB | Berdir |
#108 | entity-get-system-path-2350837-108-interdiff.txt | 2.58 KB | Berdir |
#108 | entity-get-system-path-2350837-108.patch | 95.78 KB | Berdir |
#105 | entity-get-system-path-2350837-105-interdiff.txt | 6.76 KB | Berdir |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedcatch says "critical" since we need to make sure there is not some use case that is impossible to handle with routes
Comment #2
BerdirI guess it makes sense to wait for the #type link issue before looking at this. Many usages in views related to that I think, possibly fixed there already, then a few interesting special cases, but most usage is in tests.
Comment #3
BerdirSo, the views path stuff is still there.
Another thing is the image_formatter path.
And, the path alias stuff, see PathWidget::formElement().
Most other calls should be removed.
Comment #4
BerdirWell, that was the wrong patch. Here is the patch that I wanted to upload and an additional one that includes image formatter conversion.
Comment #5
BerdirCheating a bit, but allows destination to work correctly with external-local URL's
Comment #9
dawehnerI can haz tests?
Filled a follow up: #2363459: Make it possible to provide 'langcode' in $options for URL generation instead of Language object
Lovely!
Comment #10
BerdirNot sure I like all this stuff.
Comment #12
BerdirFixing translation UI tests and the $path[0] notices.
Comment #13
BerdirGrml ;)
Comment #15
BerdirFixed a few tests, the image formatter stuff is still all weird, we should extract that in a separate issue and figure out a good solution there.
Some feedback on some of the changes here would be great, if I'm on the right track or going crazy... :)
Comment #17
dawehnerYeah just in case ... this is kinda out of scope. We explicit add kinda support for it, or at least should. It is though worth to do that in a none critical issue.
... Opened up #2363459: Make it possible to provide 'langcode' in $options for URL generation instead of Language object in order to fix that non-perfect API.
I could easily imagine this to be a usecase ... are we sure we cannot support it?
This is totally okay given that this is not a base level test API
I kinda thing we should update the documentation of
drupalGet()
I actually kinda like how php can deal with strings.
It is hilarious that we use a deprecated method as central point of our testing infrastructure.
Filled a follow up here: #2372899: PageCacheTagsTestBase should use Url objects
Comment #18
Berdir1. No it is not out of scope as it conflicts with the added leading / logic, this now assumes that it is a full url that does not need the prefix anymore, so it breaks badly. If there are better ways for that, great, but this is what we discussed and so we need it for now.
3. I removed the test because we now just have a url string that is passed through and not processed in any way. If you add 'drupal is awesome' there, it will happily print that out as a link. So testing it like that is pointless IMHO.
5. Sure we should, most of the stuff in this issue is very experimental, not going to bother with good documentation before we have a green patch and agreed on the approach. Btw, this is exactly the code that requires the changes in 1.
7. Yes :)
Also, we need to split those changes up, the image stuff needs to be a separate issue, and it's not correct yet, stuff is still breaking.
Just a re-roll for now.
Comment #20
dawehnerAlright, not a problem at all
Comment #21
xjmComment #22
BerdirRe-roll.
Comment #24
pfrenssenGoing to continue on the path that has been taken, will see if I can get some progress done on the NodeTranslationUiTest. This is a very slow test to run so it would be good to get this over with.
Comment #25
pfrenssenWasn't able to make any meaningful progress. The code sprint is at its end now, unassigning as I won't have much time in the near future.
Comment #26
dawehnerApart from these testbot details, this looks really great!
instead you could also use $entity->urlInfo()->setAbsolute()->toString() (with toString() being optional).
I'm a little bit suprised that it used to work :)
This is one of the remaining one in the other _url issue: yeah!!
Is there a reason why we removed that test coverage? I would assume that we say that we just support everything
\Drupal\Core\Url
anyway?Do we still need this here?
Comment #27
BerdirThanks.
1. Not sure that's really easier?
4. You asked the same a month ago in #17.3, see explanation in #18 :)
5. There some URL's where it is not easy to get a route for, like dblog/ID and 'entity/' . $entity_type, as they are dynamically defined in rest resource plugins.
Looking at the test failures...
Comment #28
BerdirHaving trouble running those tests with a prefix locally but let's see what this fixes.
@dawehner: Can you have a look at the failing unit and views test? I don't think that what the unit test is testing still makes sense with the updated implementation and no idea what the views test is doing exactly :)
Comment #30
BerdirOh, #26.2 actually does *not* work when you install drupal in a subdirectory. I have no idea how HEAD is passing with that, but I had a test fail in my project when going to comment/ID#comment-ID.
Comment #31
dawehnerFixed some test failures.
Comment #33
dawehnerThere we go (hopefully)
Comment #35
dawehnerThere we go.
Comment #38
dawehnerI'm fine with the patch, it would be great if someone else coudl review my recent test fixes.
Comment #39
jibranOther then this minor issue i think it is RTBC
Can we add a issue link to this?
Comment #41
BerdirNote that we still have ~20 calls to getSystemPath() left.
Almost all of the them are in views link plugins. I assume we have to refactor how that works before we can get rid of it, and we will have to when/if we do that.
Another thing are path aliases, for which we have no solution but a major issue open somewhere.
Two more calls we can get rid of I think:
- EntityWithUriCacheTagsTestBase
- ConfigEntityTest
Which I think means we need an issue summary/plan what to do with getSystemPath() exactly.
My suggestion: Keep the method, use this issue to help getting rid of _url() calls (which also helps to explain why this is critical), deal with remaining calls in case we refactor the mentioned sub-components in separate issues.
Comment #42
dawehnerWell, there are usecases indeed where you want to get the system path (url aliases is a classical example).
Comment #44
dawehnerAlright, let's start again with a reroll first.
Comment #45
dawehnerLet's get rid of 2 uses.
Comment #48
dawehnerAnd this time with the fixes of the failures. Sorry for the noise!
Comment #49
BerdirThere are a few things in here that need a change record, probably separate ones I think
- Changed behavior with leading / for drupalGet()/Post() (must be an absolute url then)
- image formatter changes
Not sure if the base url thing also counts as that, it might make sense to deprecate it but not remove in 8.x? not sure if it needs a change record then.
Your changes look good to me in general but I won't be able to RTBC this as I've written large parts of it myself.
Comment #50
dawehnerWhile writing the change record for the image formatter I realised that we should rather use the URL object, so for example a preprocess function could still preprocess it,
like adding a new query attribute.
Comment #51
BerdirAh, Url objects have __toString(), right, then we could print it directly in twig? Works for me..
Comment #52
dawehnerYeah exactly, it will directly work.
Comment #53
dawehnerSo we need the following additional adaptions for that.
Comment #54
BerdirLooks good to me. I noticed that image-formatter.html.twig documentation still mentiones path, that should be removed there.
Also wondering if we want to restore the fragment test now that I removed, not sure.
Comment #56
dawehnerFor the fragment bit we need #2401395: <none> does not work as expected with fragments
Comment #57
dawehnerAlright, let's do it!
Comment #58
kim.pepperJust a couple of naming comments...
The scheme, host and base path?
Maybe just $baseUrl?
again, base path?
Comment #59
dawehnerThank you for your review!
Well, if you look at the implementation you will see
There is already a different concept of base url in the request context implementation of symfony.
Comment #60
mpdonadioPhpStorm is reporting 17 usages of EntityInterface::getSystemPath(), and found the string '->getSystemPath' 23 times in code. The method is still in the interface definition, and there are 3 method implementations.
Should these be part of the patch, or are they excluded and being handled in followups? If the actual removal of the method is part of the patch, should there be a CR?
Comment #61
larowlanCan't see much to nitpick here, best I could come up with:
%s/Kerne/Kernel
Extra space?
Perhaps a comment as to why this is needed?
Comment #62
larowlanFixes #60 and #61, points 1 and 2 - still needs addressing #61.3
Hoping didn't break stuff.
Comment #64
larowlanlooking at fails
Comment #65
BerdirgetSystemPath() can not be removed here. see #41.
Comment #66
larowlanPaths are a tricky one, hope this is moving in the right direction.
All I have time for today.
Comment #67
BerdirYes, they are :)
We can *not* replace those remaining calls. url() returns the full URL, including prefix, so on testbot, it is /checkout/node/1, while systemPath() is always node/1.
There is no way that this is going to work without *somehow* refactoring the alias system first, which I don't think is going to happen in 8.x. We need to go back to #59 + other fixes that you worked on.
Comment #69
larowlandoing so
Comment #70
larowlanBacked out stuff, interdiff against #59, mostly minor stuff.
Comment #71
daffie CreditAttribution: daffie commentedAre we extending an old $options array? If not can we keep the old version.
Why do we set a new $options array? As far as I can see this is not used any more.
Why is this line added to the patch?
Why are these lines added to the patch?
Why change it from once to any?
Do not use the RequestContext class directly. Create a mock.
Comment #72
dawehnerThank you for your review!
Well, we want to include absolute everywhere now, so ... meh, we could redefine them.
Note: Previously we generated the expected URl like that:
so we bypassed the API for url generation basically.
With this patch we use the api (->url()) which then requires an up to date language manager as well as language path processors, so we rebuilt the container for that.
Well, we need to setup a proper fake request now that we use the proper API.
Because the implementation itself changed ... and we no longer call the method in every case.
Thank you for being so pragmatic :)
Comment #73
mpdonadioComment #74
mpdonadioBTW, I haven't done any work on this patch, so I will do a proper review it later today. It pretty much looked RTBC last night.
Comment #75
mpdonadioWas going to nit about introducing two new uses of _url(), but these can be handled in the issues that are getting rid of them.
Code changes look good; test changes look good. Read through comments a few times which justify decisions the got made. The patch is green. Not seeing anything to prevent RTBC.
Comment #76
daffie CreditAttribution: daffie commentedCan we create a followup for the @todo.
We are expending the $options array. With which $options array are we testing. It is not clear to me.
This line is not needed any more. Can you remove it.
I do not see why this change is necessary. If I am wrong about this, can you explain it to me. Your previous explanation was for me not clear enough. Sorry.
Comment #77
dawehner#2403967: DrupalKernel should setup the request context
Alright, fixed it.
Here is the new code:
Even if it is hard to see, but there is an
elseif()
in there ... which means that$this->urlGenerator->generateFromPath()
itself is not called every time.Note, at the same time we expanded the test coverage, so we also get into the new
elseif()
in the testComment #78
Wim LeersOnly a few very silly nits
s/be absolute/contain an absolute URL/
For example, in an installation in a subdirectory "d8", it should be
Could use what you wrote in #72:
We probably want to see this documented in
::drupalGet()
's docblock?There already is an issue to clean this up, at #2372899: PageCacheTagsTestBase should use Url objects :) I'll probably take that on at a later time.
The CR looks ready: https://www.drupal.org/node/2399171
All that is missing now AFAICT is an issue to address the remaining
EntityInterface::getSystemPath()
calls (particularly those in Views) and remove that method — see #41.Comment #79
dawehnerFixed
Fixed
Expanded that part of the documentation
Fixed as well
Can we keep that hunk in for now?
The issue is NOT about remove all calls
Comment #80
Wim LeersOh, absolutely, I didn't want you to remove it!
I know! I'm asking where the issue for the next step is, where we do remove all calls. But that's something to add to the issue, not to the patch. Hence: RTBC :)
Comment #81
dawehnerWell yeah, there needs to be an issue which talkes the ONE _url call inside views field plugin to support url objects properly and then at the same rewrite all those usages of paths in views (2fun").
Comment #82
alexpottShould we be doing this in this issue or another issue? Can we get a follow up created.
Not used.
Comment #83
dawehnerOpened up a follow up: #2404601: Figure out how to best deal with RequestContext::setCompleteBaseUrl
Sadly yes, as we support paths, relative URLs and absolute URLs now.
#2404603: Add proper support for Url objects in FieldPluginBase::renderAsLink(), so we can remove EntityInterface::getSystemPath(), This should be it.
Comment #84
dawehnerHere is a patch.
Comment #85
mpdonadio@alexpott's comments looks like they have all been addressed, and I think we have all of the necessary followups created. Patch is green. Setting RTBC.
Comment #86
alexpottI'm still not comfortable with the changes to webtestbase - I've discussed it with @dawehner in IRC and we concluded that we could remove the changes and instead expand drupaGet to accept a URL object. This means that no contrib tests will be broken, there's less change and more addition.
Comment #87
dawehnerBack to RTBC based upon the IRC conversation.
Comment #89
Wim LeersRebased; had to resolve a conflict for a newline being added by #2281645: Make entity annotations use link templates instead of route names in a changed hunk. Stupid git.
Comment #91
Wim LeersA failure in
Drupal\system\Tests\Theme\EngineTwigTest
… that's unrelated. Let's see if a retest makes it green again.Comment #94
BerdirNope, that's a new test apparently that is using a leading / for a path with drupalGet(). See testTwigFileUrls().
Comment #95
Wim LeersTrivial fix, hence keeping at RTBC.
Comment #96
effulgentsia CreditAttribution: effulgentsia commentedSeems like this patch can't get around changing drupalGet() in some way to support an already generated URL. However, why overload it based on the first character of the string? Why not make this patch call
$this->drupalGet($entity->urlInfo());
instead, and change drupalGet() to overload based on whether the parameter is a URL object?Not changing issue status, since there might be a good reason, and if a committer is willing to commit as-is, I don't want to stop that.
Comment #97
Berdir@effulgentsia: We did discuss exactly that, see #86/#87. The argument against it was that we still have cases where we append a built URL with things.
I actually can't find that many of those in the patch and we should be able to build a url object for all because there has to be a matching route for it in the end (although there are some 404 and similar cases I believe), so I'm willing to give a try, but I can't say for sure when I will find time for that, possibly tomorrow.
Comment #98
dawehnerThere are really tricky cases in content translation tests.
Comment #99
BerdirOk, I'm working on this in #2082049: Ignore me: Berdir vs. Simpletest, CommentTranslationUITest is green locally, did just touch that as the content translation tests is probably the most complex.
So, still needs a fair amount of work, but I think it is do-able, will post back here later.
Comment #100
BerdirOk, let's see how this goes. Note that I reverted all the leading / test changes that were necessary before. I still think we shouldn't do that, but there is no need anymore to clean that up here.
Patch is slightly bigger, but I renamed a bunch of variables, especially in the content translation tests, to make it more consistent.
Comment #102
BerdirGrml. Stupid last minute changes.
Comment #103
dawehnerberdir++
Comment #104
alexpottDiscussed in IRC with @Berdir (great work btw) ContentTranslationDeleteForm and TermTranslationBreadcrumbTest are still using
getSystemPath
. Once this patch lands we should only have the path field plugins and views field plugins using it.Comment #105
BerdirUpdated those.
ContentTranslationDeleteForm was actually also path alias related. However, I decided to just update the 5 calls related to path aliases to $entity->urlInfo()->getInternalPath(). That's just as deprecated, but then we're at least rid of those getSystemPath() calls, that is more likely to be removed than getInternalPath().
Which means the only remaining calls are all in views link fields. Which has a follow-up: #2404603: Add proper support for Url objects in FieldPluginBase::renderAsLink(), so we can remove EntityInterface::getSystemPath().
Also updated the issue summary a bit.
Comment #107
daffie CreditAttribution: daffie commentedComment #108
BerdirOk, that was mean, there was a _url() call deep down in that assertBreadcrumbs() thing. Made that dynamic now to support URL's as well, can't see a different way without converting 100 other calls.
Comment #109
BerdirWithout debug().
Comment #110
mpdonadio#109 looks good to me. Double checked usage, and outside of the Entity code, the only remaining uses look like they are in Views related code and will be handled by the followup.
Comment #111
alexpottThis issue is a critical task and is allowed per https://www.drupal.org/core/beta-changes. Committed 28977ae and pushed to 8.0.x. Thanks!
Comment #114
Dom. CreditAttribution: Dom. commentedFollow up : #2473687: Fix @todo in BasicAuthTest