Closed (fixed)
Project:
Entity Usage
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Mar 2018 at 16:12 UTC
Updated:
21 Dec 2022 at 20:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
bryandenijsI moved the logic that finds an entity by a URL from the HtmlLink plugin to the EntityUsageTrackBase and refactored the HtmlLink and Link plugins.
Unfortunately I don't have the time and skills to create/modify the tests, so if anyone else could do that for me, that would be great!
Comment #4
bryandenijsI see the tests are failing. Don't have the time at the moment to review if it is because of the non-updated tests, or because something is really broken. Will check tomorrow.
Comment #5
seanbUpdated the patch a bit to fix small things I found and hopefully fixes the test..
Comment #7
seanbTests pass locally for me, let's try again. Added new tests while I was at it.
Comment #9
marcoscanoCouldn't test this locally, but reviewing the code, maybe the issue comes because if I recall correctly, the testbot runs the tests with a path prefix, so maybe there is a mismatch between the full URL you are saving into the field, and the one you are whitelisting in config?
Comment #10
marcoscanoLet's see if this improves anything.
Comment #12
marcoscanoComment #15
marcoscanoComment #17
marcoscanoComment #19
marcoscanoOK, giving up for now.
This is how I think it should work (and passes for me), but the testbot doesn't appear to be wanting to collaborate.
Comment #20
marcoscanoRe-rolled against recent head and (hopefully) found the problem with the test.
Comment #22
marcoscanoAre you kidding me
Comment #24
marcoscanoComment #26
marcoscanoJust realized that the failure comes in a part of the test that was already passing on d.org testbot before, so I wonder if there is indeed a regression somewhere...
Let's try again with less black magic in the regex.
Comment #28
marcoscanoInterestingly, the fact that https://www.drupal.org/project/entity_usage/issues/2952008#comment-12550349 is green demonstrates that our logic to whitelist the domain inside the test with:
works, so there must be indeed a bug in
::findEntityByUrl()when used in Link fields, in some scenarios (probably when the installation uses a subdirectory?)So we definitely need to fix that before committing this.
Comment #29
idebr commentedReroll after #2952008: Automated tests: Refactor existing and add missing coverage was committed.
Removed these conflicting lines as these were already changed in the related issue above:
Comment #31
seanbThe regex to find a entity URL seemed to break for translation routes (for example linking to node/165356/translations/add/nl/en) since the route parameters for this route are different.
I updated the regex to find entity routes and added a check for the entity type. Didn't have to to fix the test, so leaving to needs work for that.
Comment #32
bryandenijsThe
isset($matches[1])is unnecessary since thepreg_match()will return 0 (false) when no match is found. With the current pattern you can assume$matches[0-2]are always set inside this if statement.Comment #33
seanbFixed #32. Also changed the matching pattern.
Ran into an issue with the groups module. When adding content in a group, the URL is group/1/content/create/group_node:article. When linking to a URL such as this the pattern matches, but since we are creating content we don't have a ID in the route parameters.
I suggest we change the pattern to work only for entity.*.canonical routes and not worry about all kinds of other entity related routes.
Comment #34
seanbRerolled #33.
Comment #35
weynhamzRerolled #34.
Comment #36
weynhamz#3060687: Support Layout Builder relationships landed recently, it needs to update the __construct signature accordingly.
Comment #37
weynhamzThe tests run fine locally, why failed on D.O.
Comment #38
marcoscano@weynhamz thanks for your contribution!
I haven't reviewed the patch, but see #26 and #28 for more info. At that time, there seemed to be legitimate concerns about the failures on d.o indicating real issues with the logic being introduced here.
It would be helpful if you could provide interdiffs between patches, it makes it easier to identify what changed between two versions of the same patch. You can find more information about creating such a file here. Thanks!
Comment #39
weynhamz@marcoscano Thanks for point out internal diff, I will provide one for the final patch.
Meanwhile, I am just submitting a patch that just moved the code around without introducing any new changes, let's see how the test bot says about it.
Comment #40
weynhamzComment #41
weynhamzComment #42
weynhamzComment #43
weynhamzFinally, manage to find why the `testLinkTracking()` is failing on test bot.
I printed out the
$url = $link->getUrl()->toString();in\Drupal\entity_usage\Plugin\EntityUsage\Track\Link::getTargetEntities, and the path is has a `/subdirectory` prefix, which later$this->pathValidator->getUrlIfValidWithoutAccessCheck($url)would not be able to handle.https://dispatcher.drupalci.org/job/drupal8_contrib_patches/17534/artifact/jenkins-drupal8_contrib_patches-17534/artifacts/run_tests.js/simpletest_html/Drupal_Tests_entity_usage_FunctionalJavascript_IntegrationTest-32-90569414.html
I miss my bed now, continue on this tomorrow.
Comment #44
weynhamzSince `$link->getUrl()->toString()` will return a path with `subdirectory` prefix because of D.O. testbot runs in the subdirectory, and we only what to handle the situation that `$link` is actually an external absolute link, let's handle things differently then.
I will provide an interdiff if testbot is happy with this patch.
Comment #45
weynhamzIt shall pass.
Comment #46
weynhamzPatch in #40 can be considered as a reroll of #24, without any new change introduced later in #26, #29, #31, #33, #34.
Update interdiff between #40 and #45 that we know why testbot is happy with #45.
Comment #47
weynhamzAdd back new changes introduced in #26, #29, #31, #33, #34.
Expect test failing.
Comment #48
weynhamzAdd back new changes introduced in #26, #29, #31, #33, #34.
Also, add back below code that got removed in #34.
Fix a stupid mistake in #47.
Now it shall pass the tests.
Comment #49
weynhamzLet's introduce these new changes in a safe way, step by step.
Comment #50
weynhamzI am using #45 as baseline now, add interdiff of 45-49.
Comment #51
weynhamzIntroduce changes in #31 and #33, but keep the original entity match pattern.
I think the proposal in #33 about use `entity.*.canonical` route pattern would be better to handle and discuss in a separate issue because we might need to have more flexibility about the entity pattern. For example, I have a case where I am using media_entity_download and the entity pattern for that is media_entity_download.download, maybe, have it configurable somehow?
Comment #52
weynhamzFix stupid error in the last patch.
Comment #53
weynhamzAdd changes in #26.
Comment #54
weynhamzComment #55
weynhamzhttps://dispatcher.drupalci.org/job/drupal8_contrib_patches/17724/artifact/jenkins-drupal8_contrib_patches-17724/artifacts/run_tests.js/simpletest_html/Drupal_Tests_entity_usage_FunctionalJavascript_IntegrationTest-38-49315841.html
Domain handling in the new code introduced in #26 does not get along with the testbot subdirectory setup.
Comment #56
weynhamzLooks like the domain used by testbot is `php-apache-jenkins-drupal8-contrib-patches-17724/subdirectory`, we need to to support subdirectory suffixed domain.
Comment #57
weynhamzComment #58
weynhamzComment #59
weynhamzFixed testbot failure in #53.
The only thing that is not included in this patch, is the proposal in #33 about use `entity.*.canonical` route pattern, which I think should be in a separate issue to discuss.
We have a few options now.
#45: this patch just tried to move the logic to handle HTML link to the base abstract class and make the Link plugin support absolute URL as well, does not introduce any other new code changes, just as this issue's original purpose.
#49: this patch can be think as a reroll of #5, with some safe code improvements.
#52: this patch added back the changes in #31 and #33, but left behind the `entity.*.canonical` route pattern change.
And finally, this one added back the regex pattern change in #26.
Of course, testbot is happy about all of these.
Comment #60
weynhamzComment #61
weynhamzComment #62
Oscaner commentedImprovement for EntityUsage type hint to EntityUsageInterface
Comment #63
seanbRerolled for beta4.
Comment #66
ricovandevin commentedRerolled for beta7.
Comment #68
ricovandevin commentedFixed a copy/paste error.
Comment #70
marcoscanoSorry all for my late response on this. Committed to 8.x-2.x.
Thanks all for contributing!