Problem/Motivation

We have to replace all left usages of _url, just 123 of them ...

Postponed on #2369225: Add $options['base_url'] to UrlGenerator::generateFromRoute()
Postponed on #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes
Blocks #2343669: Remove _l() and _url()

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because there is no bug it is fixing, and is not a feature. Just replacing old style code.
Issue priority Critical because this blocks another critical #2343669: Remove _l() and _url()

According to https://www.drupal.org/core/beta-changes , since this is a critical, it can proceed in the beta.

Proposed resolution

Remove the majority of _url() calls. Because of specific complications for some uses, and because additional uses have crept in since the creation of this issue, the remaining uses will be handled in

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Reroll the patch if it no longer applies. Instructions Yes

User interface changes

None.

API changes

None.

CommentFileSizeAuthor
#215 interdiff-211-213.txt1.69 KBmpdonadio
#215 replace_most_existing-2364157-213.patch109.71 KBmpdonadio
#211 interdiff-207-211.txt1.63 KBmpdonadio
#211 replace_most_existing-2364157-211.patch109.17 KBmpdonadio
#207 interdiff-201-207.txt666 bytesmpdonadio
#207 replace_most_existing-2364157-207.patch108.99 KBmpdonadio
#201 replace_most_existing-2364157-201.patch108.34 KBpcambra
#201 replace_most_existing-2364157-interdiff-200-201.txt3.94 KBpcambra
#200 replace_most_existing-2364157-200.patch107.93 KBpcambra
#198 interdiff.txt1.41 KBmpdonadio
#198 replace_most_existing-2364157-198.patch107.89 KBmpdonadio
#196 replace_most_existing-2364157-196-interdiff.txt991 bytesberdir
#196 replace_most_existing-2364157-196.patch107.38 KBberdir
#185 interdiff-183-185.txt1.1 KBmpdonadio
#185 replace_most_existing-2364157-185.patch111.17 KBmpdonadio
#183 replace_most_existing-2364157-183-interdiff.txt2.47 KBberdir
#183 replace_most_existing-2364157-183.patch110.58 KBberdir
#181 replace_most_existing-2364157-181-interdiff.txt23.42 KBberdir
#181 replace_most_existing-2364157-181.patch110.55 KBberdir
#179 replace_most_existing-2364157-179-interdiff.txt682 bytesberdir
#179 replace_most_existing-2364157-179.patch90.21 KBberdir
#177 replace_most_existing-2364157-177-interdiff.txt9.41 KBberdir
#177 replace_most_existing-2364157-177.patch90.21 KBberdir
#175 replace_most_existing-2364157-175-interdiff.txt3.05 KBberdir
#175 replace_most_existing-2364157-175.patch81.96 KBberdir
#160 interdiff-151-159.txt1.17 KBmpdonadio
#160 replace_most_existing-2364157-159.patch78.92 KBmpdonadio
#152 intediff_3.txt2.68 KBnaveenvalecha
#152 replace_all_existing-2364157-151.patch78.35 KBnaveenvalecha
#146 interdiff-144-146.txt1.02 KBmpdonadio
#146 replace_all_existing-2364157-146.patch80.88 KBmpdonadio
#144 interdiff-138-144.txt16.75 KBmpdonadio
#144 replace_all_existing-2364157-144.patch80.65 KBmpdonadio
#138 interdiff-130-138.txt3.07 KBmpdonadio
#138 replace_all_existing-2364157-138.patch76.6 KBmpdonadio
#130 interdiff-121-130.txt520 bytesmpdonadio
#130 replace_all_existing-2364157-130.patch80.03 KBmpdonadio
#128 interdiff-121-128.txt520 bytesmpdonadio
#128 replace_all_existing-2364157-128.patch0 bytesmpdonadio
#121 interdiff-118-121.txt849 bytesmpdonadio
#121 replace_all_existing-2364157-121.patch80.06 KBmpdonadio
#118 interdiff-114-118.txt1.1 KBmpdonadio
#118 replace_all_existing-2364157-118.patch79.23 KBmpdonadio
#114 interdiff-109-114.txt2.53 KBmpdonadio
#114 replace_all_existing-2364157-114.patch78.13 KBmpdonadio
#109 interdiff-104-109.txt12.69 KBmpdonadio
#109 replace_all_existing-2364157-109.patch79.38 KBmpdonadio
#108 interdiff.txt1.28 KBdawehner
#107 trace.txt2.19 KBmpdonadio
#107 interdiff-104-WIP.txt12.25 KBmpdonadio
#107 2364157-WIP.patch78.95 KBmpdonadio
#104 interdiff-101-104.txt18.04 KBmpdonadio
#104 replace_all_existing-2364157-104.patch89.5 KBmpdonadio
#101 2350837+2364157.patch178.93 KBmpdonadio
#101 2364157-101.patch97.32 KBmpdonadio
#97 interdiff-95-97.txt5.06 KBmpdonadio
#97 replace_all_existing-2364157-97.patch114.83 KBmpdonadio
#95 replace_all_existing-2364157-95.patch108.87 KBmpdonadio
#92 replace_all_existing-2364157-92.patch213.08 KBmpdonadio
#90 interdiff-88-90.txt5.03 KBmpdonadio
#90 replace_all_existing-2364157-90.patch213.59 KBmpdonadio
#88 replace_all_existing-2364157-88.patch208.29 KBmpdonadio
#86 replace_all_existing-2364157-86.patch209.06 KBmpdonadio
#84 interdiff.txt1.85 KBdawehner
#84 2364157-84.patch210.86 KBdawehner
#84 interdiff.txt1.85 KBdawehner
#82 2364157-82.patch109.42 KBdawehner
#82 interdiff.txt2.38 KBdawehner
#80 interdiff.txt10.24 KBdawehner
#80 2364157-80.patch108.4 KBdawehner
#78 interdiff.txt33.33 KBdawehner
#78 2364157-78.patch99.24 KBdawehner
#76 interdiff-72-76.txt5.5 KBmpdonadio
#76 replace_all_existing-2364157-76.patch84.38 KBmpdonadio
#72 interdiff-69-72.txt22.17 KBmpdonadio
#72 interdiff-67-72.txt5.78 KBmpdonadio
#72 replace_all_existing-2364157-72.patch78.88 KBmpdonadio
#69 interdiff-67-69.txt20.03 KBmpdonadio
#69 replace_all_existing-2364157-69.patch76.71 KBmpdonadio
#67 interdiff-63-67.txt360 bytesmpdonadio
#67 replace_all_existing-2364157-67.patch56.92 KBmpdonadio
#63 replace_all_existing-2364157-63.patch56.8 KBmpdonadio
#57 replace_all_existing-2364157-57.patch58.7 KBmpdonadio
#54 interdiff-46-54.txt4.22 KBmpdonadio
#54 replace_all_existing-2364157-54.patch58.54 KBmpdonadio
#46 comm.txt4.61 KBmpdonadio
#46 interdiff-37-46.patch611 bytesmpdonadio
#46 replace_all_existing-2364157-46.patch57.96 KBmpdonadio
#37 interdiff-35-37.txt872 bytesmartin107
#37 replace_all_existing-2364157-37.patch58.74 KBmartin107
#37 diff-a-b.txt488 bytesmartin107
#37 b.txt836 bytesmartin107
#37 a.txt744 bytesmartin107
#35 interdiff-29-35.txt1.31 KBmpdonadio
#35 replace_all_existing-2364157-35.patch58.37 KBmpdonadio
#31 interdiff-29-31.txt1.59 KBmartin107
#31 replace_all_existing-2364157-31.patch58.8 KBmartin107
#29 replace_all_existing-2364157-29.patch58.42 KBmartin107
#27 interdiff-25-27.txt2.59 KBmartin107
#27 replace_all_existing-2364157-27.patch58.49 KBmartin107
#25 interdiff-18-25.txt1.01 KBmpdonadio
#25 replace_all_existing-2364157-25.patch58.48 KBmpdonadio
#20 interdiff-14-18.txt1.52 KBmpdonadio
#20 replace_all_existing-2364157-18.patch57.94 KBmpdonadio
#18 interdiff-14-18.txt1.52 KBmpdonadio
#18 replace_all_existing-2364157-18.patch57.94 KBmpdonadio
#16 interdiff-14-16.txt794 bytesmpdonadio
#16 replace_all_existing-2364157-16.patch57.09 KBmpdonadio
#14 replace_all_existing-2364157-14.patch56.2 KBmartin107
#11 interdiff-06-11.txt2.42 KBmpdonadio
#11 replace_all_existing-2364157-11.patch56.26 KBmpdonadio
#6 interdiff-4-6.txt814 bytesmartin107
#6 2364157-6.patch56.24 KBmartin107
#4 interdiff.txt7.3 KBdawehner
#4 2364157-4.patch56.25 KBdawehner
#2 2364157-2.patch49.8 KBdawehner

Comments

dawehner’s picture

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new49.8 KB

Some starting work.

Status: Needs review » Needs work

The last submitted patch, 2: 2364157-2.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new56.25 KB
new7.3 KB

Some more work and no fatal later :)

Status: Needs review » Needs work

The last submitted patch, 4: 2364157-4.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new56.24 KB
new814 bytes

small-step forward.

less brackets.

Status: Needs review » Needs work

The last submitted patch, 6: 2364157-6.patch, failed testing.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

Going to try to fix as many of the exceptions and syntax errors as possible, and then triage the fails into common groups.

dawehner’s picture

@mpdonadio++

mpdonadio’s picture

Common error #1:

Argument 2 passed to Drupal\rest\LinkManager\TypeLinkManager::__construct() must be an instance of Drupal\Core\Utility\UnroutedUrlAssemblerInterface, none given, called in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/hal/src/Tests/NormalizerTestBase.php on line 119 and definedDrupal\rest\LinkManager\TypeLinkManager->__construct(Object) Drupal\hal\Tests\NormalizerTestBase->setUp() Drupal\hal\Tests\FileNormalizeTest->setUp() Drupal\simpletest\TestBase->run() simpletest_script_run_one_test('439', 'Drupal\hal\Tests\FileNormalizeTest')

No idea what this means.

Common error #2:

Uncaught PHP Exception Symfony\Component\Routing\Exception\RouteNotFoundException: "Route "view.frontpage.page_1" does not exist." at /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal/Core/Routing/RouteProvider.php line 147

There are similar problems with bad route names. Drupal\Tests\Core\UrlTest passes, so I suspect all of these fails need test mocking for urlGenerator.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new56.26 KB
new2.42 KB

Fixed a few syntax errors. Mainly want to see what testbot says for SimpleTestBrowserTest, as I there this may be a PHP 5.4 vs 5.5 complication for me to diagnose.

My comment above about mocking is wrong, as these are all webtests (ie, simpletest) and not unit tests. I assume something is wrong with all of these in the setup to make the routes available.

mpdonadio’s picture

It looks like the view.frontpage.page_1route problem is solved by simply adding views to the list of modules installed by the test. Is this bad?

Status: Needs review » Needs work

The last submitted patch, 11: replace_all_existing-2364157-11.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new56.2 KB

Patch needed reroll, No conflicts, just auto-merging

Status: Needs review » Needs work

The last submitted patch, 14: replace_all_existing-2364157-14.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new57.09 KB
new794 bytes

I think this fixed all of the HAL failures, but need to see what TestBot says about FileNormalizeTest.

Status: Needs review » Needs work

The last submitted patch, 16: replace_all_existing-2364157-16.patch, failed testing.

mpdonadio’s picture

StatusFileSize
new57.94 KB
new1.52 KB

Now I think all of the HAL stuff is fixed.

mpdonadio’s picture

Status: Needs work » Needs review
mpdonadio’s picture

StatusFileSize
new57.94 KB
new1.52 KB

Reattaching w/ proper status for testbot to run this.

martin107’s picture

Returning to #12

It looks like the view.frontpage.page_1route problem is solved by simply adding views to the list of modules installed by the test. Is this bad?

Not bad. Using the routing is needed.. and so enabling the module is a must..

In any event - the dependencies of the test, are now apparent for the next developer to see and maybe object to..

The last submitted patch, 18: replace_all_existing-2364157-18.patch, failed testing.

mpdonadio’s picture

All of the Search fails are because the route is used in the test module, so you need to add the dependency to the search_extra_type.info.yml and not the test.

The fail in GlossaryTest was a simple type in the route name.

I am going to see if I can fix TokenReplaceTest before I post my next patch, but the error isn't obvious.

Status: Needs review » Needs work

The last submitted patch, 20: replace_all_existing-2364157-18.patch, failed testing.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
StatusFileSize
new58.48 KB
new1.01 KB

Few more fixes that were explained in #23. I expect these failures:

Drupal\language\Tests\LanguageUILanguageNegotiationTest, Drupal\language\Tests\LanguageUrlRewritingTest - The test looks correct, but it looks like Url::fromRoute is ignoring the language when it is making the link.

PageCacheTagsIntegrationTest - Something is wrong with the URL generation for the nodes; the page that gets generated is a 404.

TokenReplaceTest - I don't get what this error really means.

Unassigning myself, as I won't be able to look at this for a little while.

Status: Needs review » Needs work

The last submitted patch, 25: replace_all_existing-2364157-25.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new58.49 KB
new2.59 KB

Regarding Drupal\language\Tests\LanguageUILanguageNegotiationTest
I am posting a couple of observations, I don't regard this as anywhere near a fix....

Url::fromRoute() is used in a few places to create strings which will be compared to a reference string starting 'https:://'
well if you want that then in addition to 'https' => TRUE, another key - value pair is needed. 'absolute' => TRUE.

looking at Url::fromRoute() 'script' is not a valid option, so I have removed it..

Status: Needs review » Needs work

The last submitted patch, 27: replace_all_existing-2364157-27.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new58.42 KB

Reroll, No conflicts just merging.

Status: Needs review » Needs work

The last submitted patch, 29: replace_all_existing-2364157-29.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new58.8 KB
new1.59 KB

Like #27 this is a nudge is the correct direction not a fix, for anything...

I have correctly annotated the new function

ViewExecutable::getUrlInfo() - which highlighted to me that it returns a \Drupal\Core\Url object

Which in turn highlights that the line from TokenReplaceTest should be changed :-

-      '[view:url]' => $view->getUrlInfo('page_1')->setAbsolute(TRUE),
+      '[view:url]' => $view->getUrlInfo('page_1')->setAbsolute(TRUE)->toString(),

I am still debugging this but as the code then flows into PathPluginBase::getUrlInfo the new error results from the fact that $route_names is an empty array.

I am posting this partial update in the hope the solution will be obvious to others.

Or Maybe tomorrow night, for me.

mpdonadio’s picture

Few quick comments, but I think we need @dawehner's input here.

The absolute option for the language tests is not present it 8.0.x, so I don't see why it is needed here.

PageCacheTagsIntegrationTest is failing b/c the base URL is getting tacked on, and then drupalGet is also prepending it. So, the URL is eg

http://localhost:8888/drupal-8.0.x/drupal-8.0.x/node/1

If you change the test to

$this->drupalGet($url->setAbsolute()->toString());

then the test passes. I don't want to just change the test to make it pass w/o confirming that this is correct.

TokenReplaceTest is still a mystery. I think @martin107 is right about needing toString(), but the exception suggests a bigger problem that it can't find the route or display for 'test_tokens.page_1', which doesn't make sense.

Status: Needs review » Needs work

The last submitted patch, 31: replace_all_existing-2364157-31.patch, failed testing.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

@timplunkett set me down the right path with TokenReplaceTest; I have that fixed locally.

Looking an the language problems again to see if I can fix them before I post another patch.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new58.37 KB
new1.31 KB

This fixes PathPluginBase, which makes TokenReplaceTest pass.

Nothing looks obviously wrong with the language tests. I went through the UI, enabled language, added Italian, configured it for URL (like the tests that are failing) and the URLs, and then added the switcher block. The link for italian is wrong, so I think something is wrong with the url generator itself. Trying to raise someone on IRC to help me confirm this.

Status: Needs review » Needs work

The last submitted patch, 35: replace_all_existing-2364157-35.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new744 bytes
new836 bytes
new488 bytes
new58.74 KB
new872 bytes

Thanks, @mpdonadio and @timplunkett...

Ah its obvious when you see it... I hope the mantra of post early and post often ... is not seen as too much noise on a critical issue :)

So I am looking at the test results and the first arrays returned in error labelled PageCacheTagsIntegrationTest.php line 147
I have pretty printed the 2 arrays out to get some perspective as a.txt and b.txt with the difference file diff-a-b.txt

In short what this reveals is that the following 4 elements from the PageCacheTag are missing causing the comparison to fail

  15 => 'filter_format:basic_html',
...
  20 => 'node:1',
  21 => 'node_view',
..
  25 => 'user:2',

I can't explain the filter_fomr:basic_html thing ....But my hunch is that ....it looks like something that was working is now unexpectedly returns an empty string.
As always I hope digging into the details joggs someone's brain into providing the solution.

On a minor note I have reintroduced the annotations associated with ViewExecutable::getUrlInfo() as they were the not part of the error I made as #31 was skipped over.

Status: Needs review » Needs work

The last submitted patch, 37: replace_all_existing-2364157-37.patch, failed testing.

mpdonadio’s picture

@martin107, are you running tests locally? If so, do you see the same behavior I describe in #32 with the wrong fetched and resulting in a 404 (and hence different headers), and having ->setAbsolute() fix it?

martin107’s picture

Status: Needs work » Needs review

Regarding PageCacheTagsIntegrationTest

When I try locally ( Nov 4th 16:46 UTC+0 ) it passes locally on my machine ( with 20 passes )

In the time between last known bad [ November 4, 2014 at 10:01am ] and now there have been 4 commits.

So I am retesting ... just to make sure.

My local testing is based on php5.5.10 using run-test.sh
browser testing fails, but I think that maybe a memory allocation thing at my end...

Status: Needs review » Needs work

The last submitted patch, 37: replace_all_existing-2364157-37.patch, failed testing.

berdir’s picture

Did not look at the patch at all yet, but I suspect this overlaps quite a bit with #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes ?

dawehner’s picture

@Berdir
Well in that case the other issue is just purely named :) we are removing _url() calls, ... thought it seems to be that the amount of interaction is okayish.

@mpdonadio
Maybe you could have a look at the linked issue and figure out the exact intersections and remove it from this patch for now?

mpdonadio’s picture

@dawehner, will do. I started a bash script to identify touched files in both patches, which will make this a fairly easy task. Comments on my observations in #32 and #35 would be appreciated, too, to keep this moving.

mpdonadio’s picture

Status: Needs work » Needs review
Related issues: +#2350837: Convert most usages of EntityInterface::getSystemPath() to use routes
StatusFileSize
new57.96 KB
new611 bytes
new4.61 KB
grep -- '--- a' replace_all_existing-2364157-37.patch | sort > replace_all_existing-2364157-37.files
grep -- '--- a' entity-system-path-2350837-15.patch | sort > entity-system-path-2350837-15.files
comm replace_all_existing-2364157-37.files entity-system-path-2350837-15.files > comm.txt

Based on that, the patches only overlap on two files:

core/modules/rest/src/Tests/AuthTest.php
core/modules/node/src/Tests/NodeTranslationUITest.php

The hunks for AuthTest are similar, but different. The change in entity-system-path-2350837-15 looks more better. I will yank that out of this patch.

The hunks for NodeTranslationUITest are in different portions. That will stay, though there may be clashes later on.

Status: Needs review » Needs work

The last submitted patch, 46: interdiff-37-46.patch, failed testing.

mpdonadio’s picture

Issue summary: View changes

The last submitted patch, 46: replace_all_existing-2364157-46.patch, failed testing.

The last submitted patch, 46: replace_all_existing-2364157-46.patch, failed testing.

mpdonadio’s picture

I made an issue related to the NodeTranslationUITest failure, #2369225: Add $options['base_url'] to UrlGenerator::generateFromRoute(), as I see the same behavior in HEAD with the Language Switcher block. As I mention in that issue, I thin the core problem has to do with routes mishandling the language option, but I don't know enough about this to confirm or deny it.

I will dig into the cause of the LanguageUrlRewritingTest fail to see if it is a test problem, or a code problem. But, my first look seems to indicate that some of the tests may not be valid with proper routes / URL, so we need to decide how to handle this. I will triage this.

berdir’s picture

On #44: No, the other issue is not poorly named. It's just that getSystemPath() return values eventually have to be passed through url(), so to be able to get rid of them, we also have to remove the _url() calls down the line. I posted it because I suspected that I've already solved some problem here over there.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new58.54 KB
new4.22 KB

If #2369225: Add $options['base_url'] to UrlGenerator::generateFromRoute() gets committed, then I think this is good, and worthy of a proper review.

I removed the absolute=TRUE from LanguageUILanguageNegotiationTest, as that is not correct, and LanguageNegotiationUrl::processOutbound() will generate an absolute URL anyway for domain based negotiation. There is a slight quirk in this test with regards to running the test on something other than port 80/443, but I don't think that is worth addressing in the test per some of the other comments about "Base path gives problems on the testbot, so $correct_link is hard-coded." in that file. If desired, we could hard code the port that the test is running on into the $correct_link.

The fix to PageCacheTagsIntegrationTest() is a bit of a hack, but it is a side effect of taking a URL, converting it into a string (which prepends the base path), then using that in WebTestBase::drupalGet(), which will then call UrlGenerator::generateFromPath(), which tacks on the base path again. So, the ->setAbsolute() in the patch gets around this. I am going to experiment with this and file a new issue if warranted (pretty sure this is a patchable bug in UrlGenerator::generateFromPath() wrt the ltrim logic in the middle).

Status: Needs review » Needs work

The last submitted patch, 54: replace_all_existing-2364157-54.patch, failed testing.

mpdonadio’s picture

Issue tags: +Needs reroll
mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new58.7 KB

Status: Needs review » Needs work

The last submitted patch, 57: replace_all_existing-2364157-57.patch, failed testing.

mpdonadio’s picture

xjm’s picture

Issue tags: +Triaged D8 critical
yesct’s picture

Issue summary: View changes
Status: Needs work » Postponed
Issue tags: +blocker, +Needs reroll

adding blocker tag, since this blocks #2343669: Remove _l() and _url(), so that the d8 blockers is accurate. Remove the blocker tag when this issue is fixed, and unpostpone 2343669 if this was the last blocker of that.

yesct’s picture

Issue summary: View changes
mpdonadio’s picture

Issue summary: View changes
Status: Postponed » Needs review
Issue tags: -Needs reroll
StatusFileSize
new56.8 KB

Re-roll wasn't bad. Setting Needs Review to see where we stand on fails.

Status: Needs review » Needs work

The last submitted patch, 63: replace_all_existing-2364157-63.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Postponed

Back to Postponed. The fail in AddFeedTest is from a missing `use`. The other two are expected, and should be fixed when #2369225: Add $options['base_url'] to UrlGenerator::generateFromRoute() gets committed (I'll verify this later).

Also did a quick search, and we will need to do another pass for new uses of _url() that have crept in.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio
Issue summary: View changes
Status: Postponed » Needs work

Blocking issue was committed; will have patch soon.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new56.92 KB
new360 bytes

This should come up green. However, PhpStorm is telling me there are 55 usages left in code, and 3 in comments. I'll work on the ones outside of tests first, and get that to green. Then I will update the tests.

mpdonadio’s picture

Status: Needs review » Needs work
mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new76.71 KB
new20.03 KB

Changed my mind and did all of the tests first.

I'm wondering if we should add a static method to Url that more closely resembles _url(), that would be more generic that fromUri and fromRoute, something like

public static function fromPath($path, $options = array()) {
  $url = \Drupal::service('path.validator')->getUrlIfValidWithoutAccessCheck($path);
  if ($url === FALSE) {
    if (strpos($path, 'http://') === FALSE && strpos($path, 'https://') === FALSE) {
      $path = 'base://' . $path;
    }
    return static::fromUri($path, $options);
  }
  else {
    return $url->setOptions($options);
  }
}

From looking at the remaining usages, there seem to be a decent amount of cases where there is a string that can be a path from a route, a non-routable path, or an external path. This would make the switch easier.

Status: Needs review » Needs work

The last submitted patch, 69: replace_all_existing-2364157-69.patch, failed testing.

mpdonadio’s picture

Well that was embarrassing. I'm surprised there weren't more fails with what I just fixed...

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new78.88 KB
new5.78 KB
new22.17 KB

Small manual merge when I did the rebase this morning (just added a use to a test).

Interdiffs are before the rebase, just to show what I changed.

Tests use the `Url::fromUri('base://' . $path)->toString()` pattern, as this is what was done in earlier work.

The functions that actually fetch data use the url generator service.

tim.plunkett’s picture

  1. +++ b/core/modules/aggregator/src/Tests/FeedParserTest.php
    @@ -80,7 +81,7 @@ function testHtmlEntitiesSample() {
    +    $invalid_url = Url::fromUri('base://' . 'aggregator/redirect', array('absolute' => TRUE))->toString();
    

    This is a routed URL, I think it's aggregator_test.redirect

  2. +++ b/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml
    @@ -4,3 +4,5 @@ description: 'Support module for Search module testing.'
    +  - views
    \ No newline at end of file
    

    Just hit enter

dawehner’s picture

Assigned: mpdonadio » dawehner

Working on fixing a couple of points in my review ...

  1. +++ b/core/modules/aggregator/src/Tests/FeedParserTest.php
    @@ -7,6 +7,7 @@
     
    +use Drupal\Core\Url;
     use Zend\Feed\Reader\Reader;
     
     /**
    @@ -80,7 +81,7 @@ function testHtmlEntitiesSample() {
    
    @@ -80,7 +81,7 @@ function testHtmlEntitiesSample() {
        */
       function testRedirectFeed() {
         // Simulate a typo in the URL to force a curl exception.
    -    $invalid_url = _url('aggregator/redirect', array('absolute' => TRUE));
    +    $invalid_url = Url::fromUri('base://' . 'aggregator/redirect', array('absolute' => TRUE))->toString();
         $feed = entity_create('aggregator_feed', array('url' => $invalid_url, 'title' => $this->randomMachineName()));
    

    @tim
    No you are wrong. ... its a typo, on purpose

  2. +++ b/core/modules/node/src/Tests/NodeViewTest.php
    @@ -24,13 +26,13 @@ public function testHtmlHeadLinks() {
    -    $this->assertEqual($result[0]['href'], _url("node/{$node->id()}/revisions"));
    +    $this->assertEqual($result[0]['href'], Url::fromUri("base://node/{$node->id()}/revisions")->toString());
     
         $result = $this->xpath('//link[@rel = "edit-form"]');
    -    $this->assertEqual($result[0]['href'], _url("node/{$node->id()}/edit"));
    +    $this->assertEqual($result[0]['href'], Url::fromUri("base://node/{$node->id()}/edit")->toString());
     
         $result = $this->xpath('//link[@rel = "canonical"]');
    -    $this->assertEqual($result[0]['href'], _url("node/{$node->id()}"));
    +    $this->assertEqual($result[0]['href'], Url::fromUri("base://node/{$node->id()}")->toString());
    

    We can use routes here for all of them ... pretty sure

  3. +++ b/core/modules/rest/src/LinkManager/TypeLinkManager.php
    @@ -42,7 +53,7 @@ public function __construct(CacheBackendInterface $cache) {
       public function getTypeUri($entity_type, $bundle) {
         // @todo Make the base path configurable.
    -    return _url("rest/type/$entity_type/$bundle", array('absolute' => TRUE));
    +    return $this->urlAssembler->assemble("base://rest/type/$entity_type/$bundle", array('absolute' => TRUE));
       }
    

    It is alright to make that here, i just was not perfectly happy.

  4. +++ b/core/modules/rest/src/Tests/RESTTestBase.php
    @@ -79,14 +80,19 @@ protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) {
    -          CURLOPT_URL => _url($url, $options),
    +          CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options),
    
    @@ -97,7 +103,7 @@ protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) {
    -          CURLOPT_URL => _url($url, array('absolute' => TRUE)),
    +          CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options),
    
    @@ -111,7 +117,7 @@ protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) {
    -          CURLOPT_URL => _url($url, array('absolute' => TRUE)),
    +          CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options),
    
    @@ -125,7 +131,7 @@ protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) {
    -          CURLOPT_URL => _url($url, array('absolute' => TRUE)),
    +          CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options),
    
    @@ -138,7 +144,7 @@ protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) {
    -          CURLOPT_URL => _url($url, array('absolute' => TRUE)),
    +          CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options),
    

    I'm pretty sure that we don't want to use the url_generator here ... is there really a reason to do so?

  5. +++ b/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml
    @@ -4,3 +4,5 @@ description: 'Support module for Search module testing.'
     package: Testing
     version: VERSION
     core: 8.x
    +dependencies:
    +  - views
    \ No newline at end of file
    diff --git a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php
    

    Can we fix that here? The change was needed because we need the proper route to be there ... Given that though the question is whether we should better use a dedicated test path for that

  6. +++ b/core/modules/serialization/src/Tests/EntityResolverTest.php
    @@ -58,16 +60,16 @@ function testUuidEntityResolver() {
    -            'href' => _url('entity/entity_test_mulrev/' . $entity->id()),
    +            'href' => Url::fromUri('base://entity/entity_test_mulrev/' . $entity->id())->toString(),
    
    @@ -75,7 +77,7 @@ function testUuidEntityResolver() {
    -              'self' => _url('entity/entity_test_mulrev/' . $entity->id()),
    +              'self' => Url::fromUri('base://entity/entity_test_mulrev/' . $entity->id())->toString(),
    

    Those seems to be existing routes?

  7. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -1948,11 +1949,22 @@ protected function drupalProcessAjaxResponse($content, array $ajax_response, arr
    +    // The URL generator service is not necessarily available yet; e.g., in
    +    // interactive installer tests.
    +    if ($this->container->has('url_generator')) {
    +      $url = $this->container->get('url_generator')->generateFromPath($path, $options);
    +    }
    +    else {
    +      $url = $this->getAbsoluteUrl($path);
    +    }
    

    Mh, do we need the url generator here?

  8. +++ b/core/modules/statistics/statistics.module
    @@ -39,7 +40,7 @@ function statistics_help($route_name, RouteMatchInterface $route_match) {
    -    $settings = array('data' => array('nid' => $node->id()), 'url' => _url(drupal_get_path('module', 'statistics') . '/statistics.php'));
    +    $settings = array('data' => array('nid' => $node->id()), 'url' => Url::fromUri('base://' . drupal_get_path('module', 'statistics') . '/statistics.php')->toString());
    

    It is a shame that we havent' converted poor statistics yet.

  9. +++ b/core/modules/views/src/Tests/Plugin/ExposedFormTest.php
    @@ -130,7 +131,7 @@ public function testExposedFormRender() {
    -    $expected_action = _url($view->display_handler->getUrl());
    +    $expected_action = Url::fromUri('base://' . $view->display_handler->getUrl())->toString();
    

    Could we use $view->display_handler->getUrlInfo() for this issue?

  10. +++ b/core/modules/views/src/Tests/Wizard/BasicTest.php
    @@ -74,8 +75,8 @@ function testViewsWizardAndListing() {
    +    $this->assertLinkByHref(Url::fromUri('base://' . $view2['page[feed_properties][path]']));
    +    $elements = $this->cssSelect('link[href="' . Url::fromUri('base://' . $view2['page[feed_properties][path]'], ['absolute' => TRUE])->toString() . '"]');
    
    @@ -90,7 +91,7 @@ function testViewsWizardAndListing() {
    -    $this->assertLinkByHref(_url($view2['page[path]']));
    +    $this->assertLinkByHref(Url::fromUri('base://' . $view2['page[path]'])->toString());
    
    @@ -125,7 +126,7 @@ function testViewsWizardAndListing() {
    -    $this->assertLinkByHref(_url($view3['page[path]']));
    +    $this->assertLinkByHref(Url::fromUri('base://' . $view3['page[path]'])->toString());
    
    +++ b/core/modules/views/src/Tests/Wizard/MenuTest.php
    @@ -40,7 +41,7 @@ function testMenus() {
    -    $this->assertLinkByHref(_url($view['page[path]']));
    +    $this->assertLinkByHref(Url::fromUri('base://' . $view['page[path]'])->toString());
    

    For those we do have the information about the route name and parameters available.

mpdonadio’s picture

Yeah, we need to do a good pass through this to see where routes are available and use them when possible.

#74-4, #74-7, WebTestBase::drupalGet() uses the URL generator, so I changed those two to also use it. So, everything that does actual fetching uses the URL generator, but assertions use the URL class.

#74-9: $view->display_handler->getUrlInfo() was throwing an exception about the route for the display not being available. Head scratcher.

mpdonadio’s picture

StatusFileSize
new84.38 KB
new5.5 KB

@dawehner, if you are going to fix some of this, here is my work in progress from my repo. You should probably take a look at the new method I added to URL anyway to see if it is a good idea.

Status: Needs review » Needs work

The last submitted patch, 76: replace_all_existing-2364157-76.patch, failed testing.

dawehner’s picture

Assigned: dawehner » Unassigned
Status: Needs work » Needs review
StatusFileSize
new99.24 KB
new33.33 KB

@mpdonadio
Well I think we should really try to convert it properly and use route names.

Worked on my feedback ... sadly I don't get the BreadcrumbTest working.

Status: Needs review » Needs work

The last submitted patch, 78: 2364157-78.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new108.4 KB
new10.24 KB

... fixed a couple of more instances.

Status: Needs review » Needs work

The last submitted patch, 80: 2364157-80.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new2.38 KB
new109.42 KB

Some fixes.

Status: Needs review » Needs work

The last submitted patch, 82: 2364157-82.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.85 KB
new210.86 KB
new1.85 KB

You shall not PASS, when you break the installer.

Status: Needs review » Needs work

The last submitted patch, 84: 2364157-84.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new209.06 KB

Simple reroll b/c a new behavior in core/modules/field_ui/field_ui.js

Status: Needs review » Needs work

The last submitted patch, 86: replace_all_existing-2364157-86.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new208.29 KB

Mostly easy reroll. Few manual merges.

Status: Needs review » Needs work

The last submitted patch, 88: replace_all_existing-2364157-88.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new213.59 KB
new5.03 KB

Fixed a bunch of the easy things.

I expect two groups of fails:

ImageStylesPathAndUrlTest is failing on the non-clean URL test, because a clean URL is being generated. Didn't poke much into it.

The rest seem to be related to recursive router rebuilds. Tried a few things, but didn't fire up a debugger to really dive into where the recursion is coming from.

Status: Needs review » Needs work

The last submitted patch, 90: replace_all_existing-2364157-90.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new213.08 KB

Another reroll was needed while I was debugging this... Manual merge in EntityReferenceItem; chose what was in HEAD.

Status: Needs review » Needs work

The last submitted patch, 92: replace_all_existing-2364157-92.patch, failed testing.

berdir’s picture

This patch doubled in size in comment #84, there's a ton of changes in field_ui that doesn't seem related to this. Are you sure this isn't a bad reroll in there? My guess would be the add field patch that landed around then.

I'm wondering if we should focus on #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes first, I think that's going to get rid of quite a few _url() calls in way cleaner ways than this issue, especially in the page cache tags and rest tests. Also the WebTestBase changes I think are either very similar or actually copied from there.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new108.87 KB

Just so we have it, I took the patch from #82, applied to 9663c55, applied the interdiff from #84, and rebased against HEAD. There were a few manual merges. The patch is now about the same size.

I did not try to add in any of my changes from #90.

Status: Needs review » Needs work

The last submitted patch, 95: replace_all_existing-2364157-95.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new114.83 KB
new5.06 KB

I'll defer to those above my pay grade about whether to postpone on #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes, but a quick read of the patch does look like it would be a good idea. When I first looked at it, there was little intersection between the patches, but I think that has changed now.

However, between putting together Ikea shelves today, I picked away at the current patch and had some notes prepared that I don't want to lose...

ImageStylesPathAndUrlTest is failing on the non-clean URL test, because a clean URL is being generated. I think the problem is that ImageStyle::buildUrl() is using Url::fromUri('base://' ...) and is generating a clean URL because it is detecting that the system support clean URLs (could also be from the stream wrapper manager). Not sure what the proper way to override this is for testing purposes. I also didn't see any other similar cases in existing tests.

The REST tests are failing from a recursive router rebuild problem. As far as I can tell it is from when entity_test is enabled in the setUp. No clue why this happens. This fixes the problem, but I doubt it is a proper solution (or would be in scope of this issue):

--- a/core/lib/Drupal/Core/Routing/RouteBuilder.php
+++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php
@@ -214,7 +214,7 @@ public function getCollectionDuringRebuild() {
    * {@inheritdoc}
    */
   public function rebuildIfNeeded() {
-    if ($this->routeBuilderIndicator->isRebuildNeeded()) {
+    if (!$this->building && $this->routeBuilderIndicator->isRebuildNeeded()) {
       return $this->rebuild();
     }
     return FALSE;

Status: Needs review » Needs work

The last submitted patch, 97: replace_all_existing-2364157-97.patch, failed testing.

dawehner’s picture

@mpdonadio
What about the following idea: a) remove the intersections with the other critical b) remove the conversions which break at the moment

Just get this bit in. Further work / reviews for the other conversions could be then made more focussed ...

mpdonadio’s picture

Issue tags: +Needs reroll

Sounds like a plan. Added tag because #97 doesn't apply any more...

mpdonadio’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new97.32 KB
new178.93 KB

Not sure if this will buy us much.

lsdiff 2350837-57.patch | sort > 2350837-57.files
lsdiff 2364157-WIP.patch | sort > 2364157-WIP.files
comm -12 2350837-57.files 2364157-WIP.files > both.txt

And my notes in both.txt

a/core/modules/config/src/Tests/ConfigSingleImportExportTest.php - same fix to test; removed hunks
a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php - same fix to test; removed hunks
a/core/modules/contact/src/Tests/ContactPersonalTest.php - same fix to test; removed hunks
a/core/modules/forum/src/Tests/ForumTest.php - same fix to test; removed hunks
a/core/modules/node/src/Tests/NodeTranslationUITest.php - no overlap; kept hunks
a/core/modules/node/src/Tests/NodeViewTest.php - same fix to test, 2350837 has change; removed hunks
a/core/modules/rest/src/Tests/AuthTest.php - 2350837 has change; removed hunks
a/core/modules/rest/src/Tests/RESTTestBase.php - 2350837 has change; removed hunks
a/core/modules/simpletest/src/WebTestBase.php - one intersections on actual functions; remove second hunk
a/core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php - 2350837 has change; removed hunks
a/core/modules/system/src/Tests/ParamConverter/UpcastingTest.php - same fix to test; removed hunks
a/core/modules/system/src/Tests/Routing/RouterTest.php - same fix to test; removed hunks
a/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php - same fix to test, 2350837 has change; removed hunks

That resulted in the attached as 2364157-101.patch.

Also attached a diff when I apply 2350837-57.files and 2364157-101.patch to see what the test results are.

Status: Needs review » Needs work

The last submitted patch, 101: 2350837+2364157.patch, failed testing.

The last submitted patch, 101: 2364157-101.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new89.5 KB
new18.04 KB

Backed out change to ImagePath so that we can test unclean URLs.

Backed out change to BreadcrumbTest b/c I think #1799820: Breadcrumb doesn't get localized when displaying parent terms broke it.

I think all of the rest are recursive router rebuilds. I can't find what part of the patch is causing this, or how to fix it without the major hack from above.

Status: Needs review » Needs work

The last submitted patch, 104: replace_all_existing-2364157-104.patch, failed testing.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

I have a disconnect between my patch names and my git repo, so the last few patches above aren't ready to look at. Working on straightening all of this out.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
StatusFileSize
new78.95 KB
new12.25 KB
new2.19 KB

This should come up green, and be free of intersections with #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes.

However, please see the attached trace.txt and look at the change to Drupal\rest\Plugin\Derivative\EntityDerivative::getDerivativeDefinitions. Without that hunk, there are several test failures due to recursive router rebuild detections.

Essentially, WebTestBase::setUp() eventually leads to a drupal_flush_all_caches() after the required modules have been installed. The end of that function has a router rebuild. While rebuilding the router, Drupal\rest\Plugin\Derivative\EntityDerivative tries to get a route (entity.entity_test_mulrev.canonical) from the RouteProvider. That has a RouteBuilder::rebuildIfNeeded() call in it, so we end up with a rebuild in a rebuild.

The attached patch is a quick hack to just show that preventing the recursive rebuild makes this patch pass. Questions:

Fix this in this issue, or a new issue?

Should the fix catch the exception? If I do this, I would make a RouteBuilderException which extends \RuntimeException so we have something proper to catch.

Or, should the fix just do

--- a/core/lib/Drupal/Core/Routing/RouteBuilder.php
+++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php
@@ -214,7 +214,7 @@ public function getCollectionDuringRebuild() {
    * {@inheritdoc}
    */
   public function rebuildIfNeeded() {
-    if ($this->routeBuilderIndicator->isRebuildNeeded()) {
+    if (!$this->building && $this->routeBuilderIndicator->isRebuildNeeded()) {
       return $this->rebuild();
     }
     return FALSE;

Or, and I missing something?

dawehner’s picture

StatusFileSize
new1.28 KB

Essentially, WebTestBase::setUp() eventually leads to a drupal_flush_all_caches() after the required modules have been installed. The end of that function has a router rebuild. While rebuilding the router, Drupal\rest\Plugin\Derivative\EntityDerivative tries to get a route (entity.entity_test_mulrev.canonical) from the RouteProvider. That has a RouteBuilder::rebuildIfNeeded() call in it, so we end up with a rebuild in a rebuild.

So the underyling problem is that REST module should not rely on routes in order to build routes (see #2281645: Make entity annotations use link templates instead of route names which has the foundations to solve that properly).
The current fix is, is to be able to get the route collection during the rebuild phase. It seems to be that we could fix with just not
assuming that the route is there all the time, see interdiff.

mpdonadio’s picture

StatusFileSize
new79.38 KB
new12.69 KB

That looks like it works. I expect this to be green.

mpdonadio’s picture

dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/Url.php
    @@ -470,7 +470,13 @@ public function toString() {
    +    catch (\Exception $e) {
    +      debug($e->getMessage());
    +      return '';
    +    }
    

    Let's drop that again ...

  2. +++ b/core/modules/rest/src/Tests/CsrfTest.php
    @@ -107,7 +109,7 @@ protected function getCurlOptions() {
    -      CURLOPT_URL => _url('entity/' . $this->testEntityType, array('absolute' => TRUE)),
    +      CURLOPT_URL => Url::fromUri('base://entity/' . $this->testEntityType, array('absolute' => TRUE))->toString(),
    

    Those could be an example of which we know the the actual route name, don't we?

  3. +++ b/core/modules/system/src/Controller/DbUpdateController.php
    @@ -602,7 +602,7 @@ protected function triggerBatch(Request $request) {
    -    return batch_process('update.php/results', 'update.php/batch');
    +    return batch_process('update.php/results', Url::fromUri('base://update.php/batch'));
    

    Note: update.php is a route, so we should be able to link to it.

  4. +++ b/core/modules/update/src/Tests/UpdateUploadTest.php
    index 708d42f..5dd8d4c 100644
    --- a/core/modules/update/tests/modules/update_test/update_test.routing.yml
    
    --- a/core/modules/update/tests/modules/update_test/update_test.routing.yml
    +++ b/core/modules/update/tests/modules/update_test/update_test.routing.yml
    
    +++ b/core/modules/update/tests/modules/update_test/update_test.routing.yml
    +++ b/core/modules/update/tests/modules/update_test/update_test.routing.yml
    @@ -11,5 +11,6 @@ update_test.update_test:
    
    @@ -11,5 +11,6 @@ update_test.update_test:
         _title: 'Update test'
         _controller: '\Drupal\update_test\Controller\UpdateTestController::updateTest'
         version: NULL
    +    project_name: NULL
       requirements:
         _access: 'TRUE'
    

    can you describe why we need this here?

mpdonadio’s picture

#111-1,2,3 should be easy.

#111-4 has been in the patch since the 2364157-2.patch version. Do you recall why you added it? :) I'll yank it out.

dawehner’s picture

#111-4 has been in the patch since the 2364157-2.patch version. Do you recall why you added it? :) I'll yank it out.

HA, maybe drop it and see whether it works, otherwise keep it in :)

mpdonadio’s picture

StatusFileSize
new78.13 KB
new2.53 KB

#111:1-4 should be fixed. Wish I had remembered about the route debug info in the Console project earlier...

Status: Needs review » Needs work

The last submitted patch, 114: replace_all_existing-2364157-114.patch, failed testing.

mpdonadio’s picture

SearchPageOverrideTest and EntityResolverTest are failing because the try/catch that we removed were masking a problem.

The other failures were from #111-4: 'Some mandatory parameters are missing ("project_name") to generate a URL for route'

mpdonadio’s picture

StatusFileSize
new79.23 KB
new1.1 KB

EntityResolverTest is still failing:

Drupal\Core\Routing\RouteProvider->getRouteByName('entity.entity_test_mulrev.canonical')
Drupal\Core\Routing\UrlGenerator->getRoute('entity.entity_test_mulrev.canonical')
Drupal\Core\Routing\UrlGenerator->generateFromRoute('entity.entity_test_mulrev.canonical', Array, Array)
Drupal\Core\Url->toString()
Drupal\Core\Entity\Entity->url()
Drupal\serialization\Tests\EntityResolverTest->testUuidEntityResolver()
Drupal\simpletest\TestBase->run()
_simpletest_batch_operation(Array, '7', Array)
call_user_func_array('_simpletest_batch_operation', Array)
_batch_process()
_batch_do()
_batch_page(Object)
Drupal\system\Controller\BatchController->batchPage(Object)
call_user_func_array(Array, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

I don't see how the router is installed, is fully rebuilt, and the canonical route for entity_test_mulrev doesn't exist despite being in the entity definition.

mpdonadio’s picture

Status: Needs work » Needs review

Actually, it looks like EntityTestRoutes::routes() doesn't set up canonical routes.

Status: Needs review » Needs work

The last submitted patch, 118: replace_all_existing-2364157-118.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
Issue tags: +Needs issue summary update
StatusFileSize
new80.06 KB
new849 bytes

This should come up green.

Added Needs issue summary update since we need to document what we aren't converting right now, and get followup issues made.

dawehner’s picture

In case you have some time to fix this, here is a small nitpick.

+++ b/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php
index caea321..2912482 100644
--- a/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml

--- a/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml
+++ b/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml

+++ b/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml
+++ b/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml
@@ -4,3 +4,5 @@ description: 'Support module for Search module testing.'

@@ -4,3 +4,5 @@ description: 'Support module for Search module testing.'
 package: Testing
 version: VERSION
 core: 8.x
+dependencies:
+  - test_page_test
\ No newline at end of file

Sorry for this nitpick :)

dawehner’s picture

Issue summary: View changes

Added the list of remaining _url() calls.

aspilicious’s picture

Quoting myself from IRC

aspilicious_home: Argh...
[5:19pm] aspilicious: I still think "Url::fromUri('base://' ." is terrible DX
[5:20pm] aspilicious: It's like Url::fromPath() but not with path in the function name
[5:21pm] aspilicious: And this issue https://www.drupal.org/node/2364157#new tells us that we actually abuse that base// hack to much in core, (not even mentioning contrib)
[5:21pm] Druplicon: https://www.drupal.org/node/2364157 => Replace all existing _url calls #2364157: Replace most existing _url calls with Url objects => 123 comments, 14 IRC mentions
[5:21pm] aspilicious: or client projects

dawehner’s picture

@aspilicious
So you want to introduce Url::fromPath()? Not sure how this is related with this issue, ... we use it when we don't have routing available, like for things in REST which are not routes under the hood. Feel free to introduce an issue introducing just that.

aspilicious’s picture

I tried before... But I'll try again... But Yeah not strictly related to this issue.

dawehner’s picture

I tried before... But I'll try again... But Yeah not strictly related to this issue.

The documentation should clearly document when to use it and when to NOT abuse it.

mpdonadio’s picture

StatusFileSize
new0 bytes
new520 bytes

The rebase against 8.0.x did an automatic three-way merge, so technically this is a reroll + newline for #122. The interdiff is between my git branches after the rebase.

Status: Needs review » Needs work

The last submitted patch, 128: replace_all_existing-2364157-128.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new80.03 KB
new520 bytes

Lets try this with an actual patch.

berdir’s picture

This will need a reroll after #2281645: Make entity annotations use link templates instead of route names, I suggest you wait until #2406439: Cleanup EntityDerivative and RouteBuilderInterface is committed as well, that should get rid of that recursive router rebuild business.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio
Status: Needs review » Needs work
Issue tags: +Needs reroll

Yeah, I was expecting that, and waiting on #2406439: Cleanup EntityDerivative and RouteBuilderInterface is probably a good idea to see if we can back out that workaround. I'm also hoping #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes can get in, too, before I post another patch, just in case it introduces any problems.

dawehner’s picture

Status: Needs work » Postponed

Alright, let's wait on the other RTBC patch.

mpdonadio’s picture

Found a short time break to test this...

My reroll + a small adjustment for 2406439 is coming up green.

The reroll has two manual merges. Both keep HEAD. One essentially backs out our router rebuild workaround. The other is to use the path-style link annotation for entity_test_mulrev.

That + 2350837-95.patch (ie, the RBTC one) applies cleanly and also comes up green.

I'll unpostpone and post the proper patch tonight so people can begin reviewing again.

pwolanin’s picture

Looks like a lot of the base:// usages shouldn't be there - you don't know the route name?

tim.plunkett’s picture

  1. +++ b/core/modules/aggregator/src/Tests/FeedParserTest.php
    @@ -80,7 +81,7 @@ function testHtmlEntitiesSample() {
    +    $invalid_url = Url::fromUri('base://' . 'aggregator/redirect', array('absolute' => TRUE))->toString();
    

    This should use a route name, as per #73

  2. +++ b/core/modules/basic_auth/src/Tests/Authentication/BasicAuthTest.php
    @@ -150,7 +151,7 @@ protected function basicAuthGet($path, $username, $password) {
    +        CURLOPT_URL => Url::fromUri('base://' . $path, array('absolute' => TRUE))->toString(),
    

    This obviously can't.

  3. +++ b/core/modules/hal/src/Tests/DenormalizeTest.php
    @@ -24,7 +25,7 @@ public function testTypeHandling() {
    +          'href' => Url::fromUri('base://rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
    

    There's a chicken and egg problem here, and I don't think you can use a route name for any of these rest paths.

dawehner’s picture

This should use a route name, as per #73

Oh right we should use a route, but drop that silly comment above " // Simulate a typo in the URL to force a curl exception."

There's a chicken and egg problem here, and I don't think you can use a route name for any of these rest paths.

Well, its also just a PATH used just for the HAL respresentation and its linking internally. Its not something Drupal provides.

mpdonadio’s picture

Status: Postponed » Needs review
Issue tags: -Needs reroll
StatusFileSize
new76.6 KB
new3.07 KB

OK, latest patch based.

Rebased 130. Two conflicts. Kept HEAD for both. One essentially backs out our router rebuild workaround. The other is to use the path-style link annotation for entity_test_mulrev.

Interdiff is against the rebase. The change to NodeTranslationUITest brings it back to HEAD b/c #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes now overlaps here. The other change is to add real canonical routes for the entity_test entity types (the test types invoke ->url() in a few tests, which were the cause of exceptions).

This should come up green. This + entity-get-system-path-2350837-102.patch also came up green in my test.

All uses of base:// seem to be necessary. Once this, and similar path/route related issues, get in, I will open a followup issue to audit core for base://, and either convert to route or document why base:// is needed in each case.

berdir’s picture

  1. +++ b/core/modules/basic_auth/src/Tests/Authentication/BasicAuthTest.php
    @@ -7,6 +7,7 @@
    @@ -150,7 +151,7 @@ protected function basicAuthGet($path, $username, $password) {
    
    @@ -150,7 +151,7 @@ protected function basicAuthGet($path, $username, $password) {
         $out = $this->curlExec(
           array(
             CURLOPT_HTTPGET => TRUE,
    -        CURLOPT_URL => _url($path, array('absolute' => TRUE)),
    +        CURLOPT_URL => Url::fromUri('base://' . $path, array('absolute' => TRUE))->toString(),
             CURLOPT_NOBODY => FALSE,
    

    All the calls that are made to this method are valid route names, I believe this could be refactored to accept an Url object instead of a $path string and then just do $url->setAbsolute()->toString(), see my last patch in the getSystemPath() issue, a few similar refactorings.

  2. +++ b/core/modules/hal/src/Tests/FileNormalizeTest.php
    @@ -39,7 +39,8 @@ protected function setUp() {
         $entity_manager = \Drupal::entityManager();
    -    $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default')), new RelationLinkManager(new MemoryBackend('default'), $entity_manager));
    +    $url_assembler = \Drupal::service('unrouted_url_assembler');
    +    $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default'), $url_assembler), new RelationLinkManager(new MemoryBackend('default'), $entity_manager, $url_assembler));
    

    I hate that we create those objects here by hand in a kernel test, but I guess that is not for this issue to change.

  3. +++ b/core/modules/hal/src/Tests/NormalizerTestBase.php
    index a87554c..4be27ee 100644
    --- a/core/modules/image/src/Entity/ImageStyle.php
    
    --- a/core/modules/image/src/Entity/ImageStyle.php
    +++ b/core/modules/image/src/Entity/ImageStyle.php
    
    +++ b/core/modules/image/src/Entity/ImageStyle.php
    +++ b/core/modules/image/src/Entity/ImageStyle.php
    @@ -14,6 +14,7 @@
    
    @@ -14,6 +14,7 @@
     use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
     use Drupal\Core\Routing\RequestHelper;
     use Drupal\Core\Site\Settings;
    +use Drupal\Core\Url;
     use Drupal\image\ImageEffectPluginCollection;
     use Drupal\image\ImageEffectInterface;
     use Drupal\image\ImageStyleInterface;
    

    Looks like an unecessary change, nothing else in this file is changed, so there can't be anything using Url?

  4. +++ b/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php
    @@ -462,23 +463,22 @@ function testLanguageDomain() {
    -    $this->assertEqual($italian_url, $correct_link, format_string('The _url() function returns the right URL (@url) in accordance with the chosen language', array('@url' => $italian_url)));
    +    $this->assertEqual($italian_url, $correct_link, format_string('The Url::fromRoute() returns the right URL (@url) in accordance with the chosen language', array('@url' => $italian_url)));
    

    No "The " then. And even that doesn't really make sense. (that method does not return a URL string)

    Maybe just "The right URL ..."?

  5. +++ b/core/modules/rest/src/LinkManager/RelationLinkManager.php
    @@ -27,24 +28,33 @@ class RelationLinkManager implements RelationLinkManagerInterface {
       public function getRelationUri($entity_type, $bundle, $field_name) {
    -    // @todo Make the base path configurable.
    -    return _url("rest/relation/$entity_type/$bundle/$field_name", array('absolute' => TRUE));
    +    return $this->urlAssembler->assemble("base://rest/relation/$entity_type/$bundle/$field_name", array('absolute' => TRUE));
    

    There's an issue for this @todo that @larowlan is working on, you might want to check that affects this.

  6. +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
    @@ -99,7 +100,7 @@ public function post(EntityInterface $entity = NULL) {
    -      $url = _url(strtr($this->pluginId, ':', '/') . '/' . $entity->id(), array('absolute' => TRUE));
    +      $url = Url::fromUri('base://' . strtr($this->pluginId, ':', '/') . '/' . $entity->id(), ['absolute' => TRUE])->toString();
           // 201 Created responses have an empty body.
           return new ResourceResponse(NULL, 201, array('Location' => $url));
    

    This is strange. I don't see why this shouldn't just call $entity->url() ?

  7. +++ b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php
    @@ -132,24 +133,24 @@ function testPageCacheTags() {
    -    $this->drupalGet($path);
    +    $this->drupalGet($url->setAbsolute()->toString());
    

    Once getSystemPath() is in, you can just pass $url through here.

  8. +++ b/core/modules/system/system.module
    @@ -457,7 +457,7 @@ function system_authorized_run($callback, $file, $arguments = array(), $page_tit
    -  return batch_process($finish_url->toString(), $process_url->toString());
    +  return batch_process($finish_url->toString(), $process_url);
    

    Noticed that another call called just 'update.php/results' here, toString() would be '/update.php/results', Which one is correct?

  9. +++ b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php
    @@ -27,6 +27,15 @@ public function routes() {
    +      $routes["entity.$entity_type_id.canonical"] = new Route(
    +        $entity_type_id . '/manage/{' . $entity_type_id . '}',
    +        array('_controller' => '\Drupal\entity_test\Controller\EntityTestController::testEdit', 'entity_type_id' => $entity_type_id),
    +        array('_permission' => 'administer entity_test content'),
    +        array('parameters' => array(
    +          $entity_type_id => array('type' => 'entity:' . $entity_type_id),
    +        ))
    +      );
    

    canonical pointing to the edit form? why do we need this, and why like this and not an _entity_view?

  10. +++ b/core/modules/update/src/Tests/UpdateCoreTest.php
    @@ -190,7 +190,7 @@ function testDatestampMismatch() {
    -      ->set('fetch.url', _url('update-test', array('absolute' => TRUE)))
    +      ->set('fetch.url', Url::fromUri('base://update-test', array('absolute' => TRUE))->toString())
    

    This is a route I think, in a test module.

  11. +++ b/core/modules/views/src/Plugin/views/display/DisplayRouterInterface.php
    @@ -38,4 +38,11 @@ public function collectRoutes(RouteCollection $collection);
    +  /**
    +   * Generates an URL to this display.
    +   *
    +   * @return \Drupal\Core\Url
    +   */
    +  public function getUrlInfo();
    

    Missing description on the @return, AFAIK, only $this does not need one.

  12. +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php
    @@ -486,5 +486,15 @@ public function validate() {
    +  public function getUrlInfo() {
    +    if (strpos($this->getOption('path'), '%') !== FALSE) {
    +      throw new \InvalidArgumentException('No placeholders supported yet.');
    +    }
    

    What happens if this is called if the view has arguments?

  13. +++ b/core/modules/views/src/ViewExecutable.php
    @@ -1758,6 +1759,26 @@ public function getUrl($args = NULL, $path = NULL) {
    +    if (!$this->display_handler instanceof DisplayRouterInterface) {
    +      throw new \InvalidArgumentException(String::format('You cannot get generate a URL for the display @display_id', ['@display_id' => $display_id]));
    

    This exception message not english is :)

mpdonadio’s picture

I'll look at these, but a few quick comments.

8. The second argument to batch_process() is supposed to be a Url object.

9. This was to match the change in #2281645: Make entity annotations use link templates instead of route names where the annotation has the same path for canonical and edit form. The canonical route was needed to prevent an exception in a test, but I don't think it is used anywhere b/c it was just in a data structure.

berdir’s picture

8. I meant the first argument, not the second :)

9. Strange. Have a look at entity.routing.yml, it has the canonical route, but only for entity_test, not the others. I suggest you move that into the class and make it generic but consistent with that.

berdir’s picture

dawehner’s picture

What happens if this is called if the view has arguments?

For now we don't support this. It is a little bit tricky to convert ViewExecutable::getUrl to the logic to create url objects.

mpdonadio’s picture

StatusFileSize
new80.65 KB
new16.75 KB

OK, this should come up green

#139-1,4,6,10,11,13, done

#139-3, reverted file to HEAD, done

#139-5, checked with @larowlan on #2336247: Make Relation and Type domain configurable based on context and he said to leave this in this patch.

#139-7, added @todo

#138-8, the $finish_url in system_authorized_batch_process() comes from system_authorized_get_url(), which is authorize.php not update.php, so left this as-is

#138-9, I realized that I had duplicated that route (not sure when it came in). I reverted that file to HEAD.

#139-12, per #143, left as is

dawehner’s picture

+++ b/core/modules/aggregator/src/Tests/FeedParserTest.php
@@ -80,7 +81,7 @@ function testHtmlEntitiesSample() {
     // Simulate a typo in the URL to force a curl exception.
-    $invalid_url = _url('aggregator/redirect', array('absolute' => TRUE));
+    $invalid_url = Url::fromUri('base://' . 'aggregator/redirect', array('absolute' => TRUE))->toString();

Tim asked that multiple times now. Are you sure this is needed here? There is a routing definition for this path:

aggregator_test.redirect:
  path: '/aggregator/redirect'
  defaults:
    _controller: '\Drupal\aggregator_test\Controller\AggregatorTestRssController::testRedirect'
    _title: 'Test feed with a redirect'
  requirements:
    _access: 'TRUE'
mpdonadio’s picture

StatusFileSize
new80.88 KB
new1.02 KB

Cleared up some confusion on my end w/ FeedParserTest::testRedirectFeed(). There was a small manual merge needed when I rebased, so the interdiff is a `git diff` just against the file that I changed.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I'm fine with this, as it is now.

naveenvalecha’s picture

Issue summary: View changes

@mpdonadio,
Are we going to inroduce the Url::fromPath() that's why we are not going to remove the all calls ?

Updated the issue summary #121.
Added the beta changes section as well.
Not removing the tag right now as it need to create another follow up issues to convert remaining _url() calls and also need to update the follow up issues as well.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/includes/form.inc
    @@ -815,13 +823,16 @@ function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = NU
    -        $function($batch['url'], $options);
    +        $function($batch_url, ['query' => $query_options]);
    

    Unless we want a CR here then we should do $batch_url->toString() here. Unfortunately, as far as I can see, this redirect_callback is completely unused, untested and undocumented so whilst it might be nice to just pass the Url object alone I think this is the best option.

  2. +++ b/core/modules/system/tests/modules/session_test/session_test.module
    @@ -1,9 +1,10 @@
    +use Drupal\user\UserInterface;
    ...
    -function session_test_user_login($account) {
    +function session_test_user_login(UserInterface $account) {
    
    +++ b/core/modules/update/tests/modules/update_test/update_test.routing.yml
    @@ -11,5 +11,6 @@ update_test.update_test:
    +    project_name: NULL
    
    +++ b/core/modules/user/user.api.php
    @@ -1,6 +1,7 @@
    +use Drupal\user\UserInterface;
    
    @@ -132,7 +133,7 @@ function hook_user_format_name_alter(&$name, $account) {
    -function hook_user_login($account) {
    +function hook_user_login(UserInterface $account) {
    
    +++ b/core/modules/user/user.module
    @@ -616,7 +616,7 @@ function user_login_finalize(UserInterface $account) {
    -function user_user_login($account) {
    +function user_user_login(UserInterface $account) {
    
    

    This all looks unrelated to me

  3. +++ b/core/modules/views/src/ViewExecutable.php
    @@ -1758,6 +1759,26 @@ public function getUrl($args = NULL, $path = NULL) {
       /**
    +   * Gets the Url object associated with the display handler.
    +   *
    +   * @param string $display_id
    +   *   (Optional) The display id. ( Used only to detail an exception. )
    +   *
    +   * @throws \InvalidArgumentException
    +   *   Thrown when the display plugin does not have a URL to return.
    +   *
    +   * @return \Drupal\Core\Url
    +   *   The display handlers URL object.
    +   */
    +  public function getUrlInfo($display_id = '') {
    +    $this->initDisplay();
    +    if (!$this->display_handler instanceof DisplayRouterInterface) {
    +      throw new \InvalidArgumentException(String::format('You cannot generate a URL for the display @display_id', ['@display_id' => $display_id]));
    +    }
    +    return $this->display_handler->getUrlInfo();
    +  }
    

    Only for one test? (TokenReplaceTest) Can't we just to this in the test?

  4. The issue summary and title need fixing - we still have _url calls after applying this patch - 33 of them.
naveenvalecha’s picture

Issue summary: View changes

Removed the special characters from the html.
Yeah #149-2 will address with that because these are not related to this patch.

mpdonadio’s picture

Title: Replace all existing _url calls » Replace most existing _url calls with Url objects
Assigned: mpdonadio » Unassigned
Issue summary: View changes
Status: Needs work » Postponed

OK, I am postponing again on #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes so we can get an accurate list of remaining _url() uses, and get the followups made.

#149:1,2 should be easy.

I am deferring to @dawehner on #149-3.

naveenvalecha’s picture

Issue summary: View changes
StatusFileSize
new78.35 KB
new2.68 KB

1)Addressed the #149-2 that makes more sense and not related to this stuff.
The interdiff is not same as specified https://www.drupal.org/documentation/git/interdiff I accidently committed the changes in the same new local branch.
So I created a new branch and apply the #149 patch to it.and then commit the changes to it and then create the patch by diff oldbranch new branch
Instructions followed :

  1. git checkout -b 2364157-149
  2. git apply -v replace_all_existing-2364157-146.patch
  3. git commit -m "Applied changes."
  4. Did the changes as specified in the #149-2
  5. git commit -am "Applied the #149-2 suggested changes"
  6. git checkout 8.0.x
  7. git checkout -b 2364157-149-old
  8. git apply -v replace_all_existing-2364157-146.patch
  9. git commit -m "Applied changes."
  10. Interdiff : diff replace_all_existing-2364157-146-old.patch replace_all_existing-2364157-146.patch > intediff.txt
  11. Patch : git diff 8.0.x > replace_all_existing-2364157-146.patch

Is there any better option to do if accidently commit the changes in the same issue old branch ?

2)#149-4
Updated the issue summary with the function usages in call and as well in comments.
Will need to create the child issues.how should the follow ups be created ?
Should be 7 followups for different components ?
1)For core/inlcudes/common.inc
2)core/module/image
3)core/module/node
4)core/module/rest
5)core/module/simpletest
6)core/module/system
7)core/module/views

yesct’s picture

Status: Postponed » Needs review

changing to needs review so the bot will run.
will change it back.

about to update the beta evaluation.

---
you could have made the interdiff by git diff'ing the two branches. :) Next time.

yesct’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

updated beta evaluation (and put it in the motivation, where Contributor task: https://www.drupal.org/contributor-tasks/update-allowed-beta says to put it, and so it doesn't get lost after the long list of usages)

yesct’s picture

Status: Needs review » Postponed

Status: Postponed » Needs work

The last submitted patch, 152: replace_all_existing-2364157-151.patch, failed testing.

The last submitted patch, 152: replace_all_existing-2364157-151.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new78.92 KB
new1.17 KB

The change to update_test.routing.yml is needed.

This patch includes #149-1, #149-2, and will come up green.

Will postpone when TestBot is done.

mpdonadio’s picture

Status: Needs review » Postponed

Back to Postponed on #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes, as that removes some _url() calls and (unfortunately) introduces a few more (three last time I counted). When we get the final list, I will triage them into groups, and have a followup for each to keep things manageable. I anticipate one for

  • Views
  • File/Image
  • Everything else

However, I think the first two in this list may need to be postponed on #2405551: Add a method to support UIs where users enter paths instead of route names and other valid use cases.

I am deferring to @dawehner on #149-3 to weigh in before we make the (hopefully) final version of this patch, but I think we will want this method in ViewExecutable in the long term, as I think we will probably want/need it for some of the remaining routing/menu issues.

berdir’s picture

Status: Postponed » Needs work

#2350837: Convert most usages of EntityInterface::getSystemPath() to use routes got in!

Which means that needs needs a reroll for sure and then we need to check if we really got all _url() calls.

berdir’s picture

Assigned: Unassigned » berdir
Issue tags: +SprintWeekend2015

I'll do a reroll of this.

berdir’s picture

Assigned: berdir » Unassigned

Actually, the patch applies, but we still have 30 calls to _url().

borisson_’s picture

Assigned: Unassigned » borisson_
borisson_’s picture

Assigned: borisson_ » Unassigned

Follow up issues should be created for the remaining _url calls.

[14:14:48] Borisson_: and deal with the other ones later, as they will require much more work
[14:15:04] Borisson_: so I would suggest to create follow ups for all the remaining _url calls, does that sound sane?
[14:15:32] I've found 23 usages, so 23 new issues?
[14:16:25] Borisson_: I guess we maybe can group them a bit?

mpdonadio’s picture

Status: Needs work » Needs review

Yeah, see #161. When I get a chance later this morning, I will look at the remaining usages, update the issue summary, and get the followups made.

The current patch does needs review, though, and input about `ViewExecutable::getUrl()` should stay there be moved to the test.

mpdonadio’s picture

Issue summary: View changes
mpdonadio’s picture

I updated the issue summary to the best of my ability, and created followup issues.

The change to update_test.routing.yml was needed. That remains in the current patch.

@dawehner discussed this in IRC, and while `ViewExecutable::getUrl()` is currently only used in test, the functionality is in line with what this patch does and we will need this down the road for non-test code.

yesct’s picture

so... this is a meta and will not have a patch? wait .. #170 says there will be a patch for update_test.routing.yml so... what should the title be?
How is this different from #2409233: Remove remaining _url() calls not covered by other issues?

mpdonadio’s picture

This is not a meta issue. #160 has the latest patch. This morphed from a "replace all" to "replace most, with followup issues" to account for some very specific and difficult problems with getting rid of _url(), and to account for new uses of _url() that have crept in, and account for how other patches have changed a bit over time. Doing everything in a single patch has become too difficult.

This issue now gets rid of most uses of _url(). The three followups issues get rid of the rest. The Views and Image followups are for two difficult cases. The third, 9209233, is to get rid of the stragglers.

berdir’s picture

I'm not sure about all those follow-ups. How is #2409233: Remove remaining _url() calls not covered by other issues different from this issue, for example?

Closing one critical just to end up with 3 additional ones doesn't really help us, especially if it is not one specific usage. I can see an argument for getting a part of the patch in to to make reviews of the remaining stuff easier, but maybe we can commit that here and just keep the issue going. Or we can open a separate issue to get those in. Not sure.

I will try to take a look at the remaining cases today, if I don't get distracted too much.

berdir’s picture

That said, I see the point of the views follow-up, because that needs #2404603: Add proper support for Url objects in FieldPluginBase::renderAsLink(), so we can remove EntityInterface::getSystemPath(), but maybe we can fix both _url() and getSystemPath() calls in that same issue instead of two?

berdir’s picture

One down, this fixes the image style URL. Maybe we want to do more cleanup there, and extract the common logic there into RequestContext or so, I copied this from generateFromPath(). This would also partially at least solve system_js_alter().

Status: Needs review » Needs work

The last submitted patch, 175: replace_most_existing-2364157-175.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new90.21 KB
new9.41 KB

Fixed the installer and updated rest tests. Was debugging this for a long time because I didn't clone the URL at first.

Status: Needs review » Needs work

The last submitted patch, 177: replace_most_existing-2364157-177.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new90.21 KB
new682 bytes

Stupid typo.

Note: For the base:// added in rest tests, we could add a httpRequestWithBasePath() or something as a wrapper, but I think an easier to use helper method is being worked on anyway.

Status: Needs review » Needs work

The last submitted patch, 179: replace_most_existing-2364157-179.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new110.55 KB
new23.42 KB

Ok, fixed some tests, tried to update system_js_alter(), not exactly sure if this is going to work, we'll see.

Also updated a lot of stale documentation references.

As far as I can see, we now have three cases left:

- page cache tags, we have an issue for this. Should not be too hard to do, but might result in quite some changes: #2372899: PageCacheTagsTestBase should use Url objects, so that might be a useful follow-up. Or we could just bake in a Url::fromUri() there.
- Breadcrumbs.. similar but worse, dozens of hardcoded path calls. Easiest fix might be a few Url::fromUri() call there.
- Views.. well, yeah.
- ( few left referenced inside places like _l(), that should go away themself as well.

Status: Needs review » Needs work

The last submitted patch, 181: replace_most_existing-2364157-181.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new110.58 KB
new2.47 KB

Fixing test fails.

I also posted a patch to #2372899: PageCacheTagsTestBase should use Url objects.

Status: Needs review » Needs work

The last submitted patch, 183: replace_most_existing-2364157-183.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new111.17 KB
new1.1 KB

Simple fix to DeleteTest for the entity that does not exist, and checking for 405 when trying to delete a resource which is not REST API enabled (405 is Method Not Allowed).

berdir’s picture

Here's an attempt at using Url::fromUri() instead of generateFromPath().

I updated the _url() calls in the menu tests, and I also added back support for system paths to rest tests, after thinking about it, I don't see anything wrong with that, given that we continue to support it in the same way in drupalGet(). I added a new helper method called buildUrl(), not too happy about that, maybe builtAbsoluteUrl(), but the problem is that we already have getAbsoluteUrl(), which is now used by buildUrl(). Any suggestions on the naming there?

Status: Needs review » Needs work

The last submitted patch, 186: replace_most_existing-2364157-186.patch, failed testing.

mpdonadio’s picture

REST tests. Was going to make this suggestion and add it, but didn't see you in IRC at the time.

How about buildTestUrl() or buildPathforTest()? Something that suggests that this code just for testing purposes and not to be used as sample code? Could this also replace a lot of the `Url::fromUri('base:://' . $path)->toString()` that are all over the tests, maybe with a parameter to enable (or disable) the absolute path?

@@ -70,7 +71,7 @@ protected function assertBreadcrumbParts($trail) {
       foreach ($trail as $path => $title) {
         // If the path is empty or does not start with a leading /, assume it
         // is an internal path that needs to be passed through _url().
-        $url = $path == '' || $path[0] != '/' ? _url($path) : $path;
+        $url = $path == '' || $path[0] != '/' ? Url::fromUri('base:://' . $path)->toString($path) : $path;
         $part = array_shift($parts);
         $pass = ($pass && $part['href'] === $url && $part['text'] === String::checkPlain($title));
       }

Accidentally added $path to the ->toString() call.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new107.35 KB
new3.58 KB

Haha, painfully stupid. Changed everything 3 times, only to end up with base::// everywhere.

berdir’s picture

Crossposted with the review. Fixed the additional $path there.

The last submitted patch, 189: replace_most_existing-2364157-188.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 190: replace_most_existing-2364157-189.patch, failed testing.

berdir’s picture

Ok, looks like fromUri() doesn't work, it can't handle an empty string for example (= frontpage). I think we nee to go back to generatorFromPath() unless @dawehner has an idea?

dawehner’s picture

Status: Needs work » Needs review

I'd be fine with as it is, given that it is quite some progress.

mpdonadio’s picture

Issue summary: View changes

Updated IS to remove outdated / unneeded child issues.

berdir’s picture

Reverted buildUrl() back to use the url generator.

@dawehner: Ok. But all the other changes that I made in those patches are still useful, it is hopefully just this part that is hard.

Status: Needs review » Needs work

The last submitted patch, 196: replace_most_existing-2364157-196.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new107.89 KB
new1.41 KB

Adjusted some logic in AssertBreadcrumbTrait.

jibran’s picture

Status: Needs review » Needs work

This is close just few minor points left.

  1. +++ b/core/includes/form.inc
    @@ -815,13 +823,16 @@ function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = NU
    +        $batch_url->setAbsolute();
    +        return new RedirectResponse($batch_url->toString());
    

    We can do this in one line.

  2. +++ b/core/includes/install.core.inc
    @@ -581,10 +582,10 @@ function install_run_task($task, &$install_state) {
    +      $response = batch_process($url, clone $url);
    

    According to the function doc of batch_process 1st @param is path we are passind Url object here. Either docs are wrong or this is wrong.

  3. +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
    @@ -251,7 +251,7 @@ public function generateFromPath($path = NULL, $options = array()) {
    +      // would require another function call, and performance inside this is
    

    and performance here is OR and performance is critical here.

  4. +++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php
    @@ -155,13 +155,24 @@ protected function buildLocalUrl($uri, array $options = []) {
    +    if (!empty($base_path_with_script)) {
    +      $script_name = $request->getScriptName();
    +      if (strpos($base_path_with_script, $script_name) !== FALSE) {
    +        $current_script_path = ltrim(substr($script_name, strlen($current_base_path)), '/') . '/';
    

    Please add comments here.

  5. +++ b/core/modules/hal/src/Tests/NormalizerTestBase.php
    @@ -134,7 +134,8 @@ protected function setUp() {
    +    $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default'), $url_assembler), new RelationLinkManager(new MemoryBackend('default'), $entity_manager, $url_assembler));
    

    Please add @see to LinkManager class.

  6. +++ b/core/modules/image/src/Entity/ImageStyle.php
    @@ -218,12 +219,12 @@ public function buildUrl($path, $clean_urls = NULL) {
    +    // ensure that it is included. Once the file exists it's fine to fall back to the
    

    more then 8 chars.

  7. +++ b/core/modules/path/src/Tests/PathLanguageTest.php
    @@ -118,11 +118,11 @@ function testAliasTranslation() {
    +    // Confirm that the alias is returned for the URL. Languages are cached on
    

    doesn't make sense is it for or from?

pcambra’s picture

Status: Needs work » Needs review
StatusFileSize
new107.93 KB

Plain reroll

pcambra’s picture

Fixed, 1, 3, 5 & 6 from #199.

Regarding 2:

According to the function doc of batch_process 1st @param is path we are passind Url object here. Either docs are wrong or this is wrong.

Added a Url|string in the docs as _batch_finished() is the only place where 'batch_redirect' is used, and it handles both Urls and paths.

4 and 7 are still to do.

The last submitted patch, 200: replace_most_existing-2364157-200.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 201: replace_most_existing-2364157-201.patch, failed testing.

pcambra’s picture

Seems like this one has affected here: #784626: Default all JS to the footer, allow asset libraries to force their JS to the header

Also related? #1547376: Allow url() or some other function to return individual components of an outbound URL

The fail is happening here:

+++ b/core/modules/system/system.module
@@ -631,7 +631,7 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
-  _url('', array('script' => &$scriptPath, 'prefix' => &$pathPrefix));
+  Url::fromRoute('<front>', [], array('script' => &$scriptPath, 'prefix' => &$pathPrefix))->toString();

The last submitted patch, 198: replace_most_existing-2364157-198.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new108.99 KB
new666 bytes

The exception leads to the real culprit. You need the router schema and to rebuild the route tables.

I wonder if we should add these two lines to KernelTestBase::setUp and WebTestBase::setUp, and remove from the individual tests? This is bound to happen in the future.

Didn't look at anything else; just fixed that test (AttachedAssetsTest came up green locally).

dawehner’s picture

 // @see \Drupal\rest\LinkManager\LinkManager()
+    $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default'), $url_assembler), new RelationLinkManager(new MemoryBackend('default'), $entity_manager, $url_assembler));
 

IMHO, 100% pointless. There is a new statement, we know exactly which class we talk about already.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

I'll touchup the last few things and get a patch posted tonight.

Any thoughts on adding

$this->installSchema('system', array('router'));
$this->container->get('router.builder')->rebuild();

to KernelTestBase::setUp and WebTestBase::setUp to prevent the router exceptions in new tests that get added in the future that use Url()::fromRoute()?

berdir’s picture

Not related to this issue. Web tests have that anyway, it would only be kernel tests that would need it. Agreed that it would be useful there, but not sure about installing the table by default, we try to make kernel tests as fast as possible, with some DX costs for installing tables and so on.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
StatusFileSize
new109.17 KB
new1.63 KB

#199-4 is done. Not sure if someone has a better way to explain this.

I think the language in #199-7 is fine as-is.

#208 is done.

Also did a search for "Url::fromUri('base://" and all of the uses we introduce look legit.

dawehner’s picture

Maybe we can finally nail it down.

  1. +++ b/core/lib/Drupal/Core/Asset/CssOptimizer.php
    @@ -138,10 +138,10 @@ protected function loadNestedFile($matches) {
    +    // the url() path.
    ...
    -    // Alter all internal _url() paths. Leave external paths alone. We don't need
    +    // Alter all internal url() paths. Leave external paths alone. We don't need
    

    Good catches, this is not about PHP url()

  2. +++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php
    @@ -155,13 +155,28 @@ protected function buildLocalUrl($uri, array $options = []) {
    +    $request = $this->requestStack->getCurrentRequest();
    +    $current_base_path = $request->getBasePath() . '/';
    +    $current_script_path = '';
    +    $base_path_with_script = $request->getBaseUrl();
    +
    +    // If the current request was made with the script name (eg, index.php) in
    +    // it, then extract it, making sure the leading / is gone, and a trailing /
    +    // is added, to allow simple string concatenation with other parts.
    +    if (!empty($base_path_with_script)) {
    +      $script_name = $request->getScriptName();
    +      if (strpos($base_path_with_script, $script_name) !== FALSE) {
    +        $current_script_path = ltrim(substr($script_name, strlen($current_base_path)), '/') . '/';
    +      }
    +    }
    +
         // Merge in defaults.
         $options += [
           'fragment' => '',
           'query' => [],
           'absolute' => FALSE,
           'prefix' => '',
    -      'script' => '',
    +      'script' => $current_script_path,
    

    It would be great to describe why we need to add it here.

  3. +++ b/core/modules/rest/src/Tests/DeleteTest.php
    @@ -7,6 +7,7 @@
    +use Drupal\core\Url;
    

    ... Please let's use Drupal\Core\Url

  4. +++ b/core/modules/rest/src/Tests/DeleteTest.php
    @@ -70,9 +71,9 @@ public function testDelete() {
    -    $this->httpRequest('entity/user/' . $account->id(), 'DELETE');
    +    $this->httpRequest($account->urlInfo(), 'DELETE');
         $user = entity_load('user', $account->id(), TRUE);
         $this->assertEqual($account->id(), $user->id(), 'User still exists in the database.');
    -    $this->assertResponse(404);
    +    $this->assertResponse(405);
    

    Can someone explain why the behaviour changed?

berdir’s picture

4. Because the old path was bogus. The test was supposed to test that it is no longer possible to access that resource after it was disabled, but it used the old path with the entity/ prefix, which is always 404, resource enabled or not :)

dawehner’s picture

@Berdir
Yeah @mpdonadio explained it me in person.

mpdonadio’s picture

Issue tags: +D8 Accelerate NJ
StatusFileSize
new109.71 KB
new1.69 KB

#212-2, made comment better

#212-3, was unused, so removed

#212-4, this is the proper behaious. The user exists, but the DELETE action doesn't exist for it.

Also added a proper Url() object per a verbal comment.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Let's get crazy tonight

webchick’s picture

Status: Reviewed & tested by the community » Fixed

You know what? Let's do this. We may find we have more clean-up to do here, but it'll be much easier to do in smaller, targeted follow-up issues.

Committed and pushed to 8.0.x. YEAH! Awesome work, everyone.

  • webchick committed 0fb9bb5 on 8.0.x
    Issue #2364157 by mpdonadio, dawehner, martin107, Berdir, pcambra,...

Status: Fixed » Closed (fixed)

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