Closed (fixed)
Project:
Drupal core
Version:
9.2.x-dev
Component:
taxonomy.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
11 Sep 2018 at 16:16 UTC
Updated:
10 May 2021 at 08:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
5n00py commentedComment #3
5n00py commentedComment #4
cilefen commentedComment #5
cilefen commentedComment #7
hctomThe provided patch is not applyable via Composer because it was created relative to the
coredirectory. Here is a new patch that should work with ComposerComment #8
hctomComment #10
chipway commentedHere is a new patch to change deprecated ContextDefinition to EntityContextDefinition.
Please review.
Comment #12
chipway commentedNew patch.
Comment #13
chipway commentedComment #14
hctomJust found an unused use statement, that I removed as well with this updated patch
Comment #16
hctomI just found some more occurrences of
nodein the comments, so here is a new patch, also fixing them - so forget about the last submitted patch.Comment #17
hctomI finally made it to use the context in one of my projects and found a missing use statement. So here is an updated patch fixing the associated PHP error
Comment #18
5n00py commentedLooks good.
Do we need some tests ?
Comment #19
hctomI guess so. I tried to figure out how the node module tests its context provider, but I did not find any clue about it. If you have any idea, please let me know ;)
Comment #20
rlhawkI don't see any tests specific to the Node Route context.
One thing I noticed about the definition for that context, though, is that there is special consideration given for the node.add route:
Perhaps this should be implemented for the Term Route context also, although the route would need to be "entity.taxonomy_term.add_form".
Comment #21
andyg5000Commerce module provides good examples of testing context. #2984280: Allow SKU to be used in loadFromContext has an example of a test I wrote to extend their context. Thanks for the work on this!
Comment #22
hctomOkay, so first, here is an updated patch with the context for the
entity.taxonomy_term.add_formroute.@andyg5000: Thanx for your input regarding tests, but isn't that a completely different scenario in your patch? It takes a value from an URL query string parameter there and calls a variation storage method to get the comparison value. I think this does not cover the context provider case we have here, or am I wrong?
Comment #23
hctomReorder files correctly ;)
Comment #24
andyg5000Hey @hctom, you're correct, sorry for the confusion. I forgot that test is expecting a query parameter. I couldn't find an example in the node module either. If I find a better example or can hack out the test myself, I'll report back.
Comment #26
mpolishchuck commentedHello everyone.
Glad to see that somebody has created this issue already (I mean I'm not only who needs it).
After reading the patch in #22 I have only one question.
Why does context provider create context named term, but not taxonomy_term? The entity type is named taxonomy_term. And if we look in contrib modules (I've looked into webform and commerce), the contexts always named the same as entity type. Is there specific reason to name it term, but not taxonomy_term? Or it is just mistake?
Comment #27
mpolishchuck commentedAdding updated version of the patch. It's exactly the same as #22, but creates taxonomy_term instead of term.
Comment #28
hctomThat's a good point and I am not really sure, why this was in the code like that ;) I guess it was a leftover from the initial patch. But I just checked your patch and it still seems to work without problems, so I am just uploading the missing interdiff here, to allow easy code comparison between patches.
Comment #29
hctom...and lets hide some old patch versions ;)
Comment #30
evilehk commentedThe patch from #27 rebased against 8.8.x.
Comment #31
evilehk commentedAdds Kernel test covering TermRouteContext class.
Comment #32
5n00py commentedLooks good. +1 for rtbc.
Comment #33
fallenturtle commentedI can confirm path 31 worked for me. Does something else need to happen before its changed to RTBC?
Comment #35
duaelfrGood job here! This looks really good to me. It has tests and works well so let's go RTBC!
I did a side-by-side comparison with
\Drupal\node\ContextProvider\NodeRouteContextand these two classes are quite similar. It should open a way to a standardisation in a follow-up (that might already exist).One nitpick that can be fixed on commit, though: uses are supposed to be sorted alphabetically.
Comment #37
hctomGive me a second, and I'll give you an updated patch ;)
Comment #38
hctom...and here it is ;) Use statements should be sorted correctly now and deprecation notices should be gone.
Comment #39
hctomWhoops.. I created the interdiff the wrong way around, so here is the correct one!
Comment #40
duaelfrStill looks good and tests are green so back to RTBC!
Thanks
Comment #41
catchIs there logic here that we could move to a trait or base class and re-use in the node route context or other ones? Not sure it's worth the effort of making it generic, but maybe?
Comment #42
catchComment #43
tim.plunkettTrait didn't work as well as a base class did. Maybe it's overkill, idk.
Comment #44
evilehk commentedI think the recent changes to move the entity route context into a base class is great and not an overkill at all! It prevents the mostly duplicate code between NodeRouteContext and TermRouteContext. There was a variable named 'term' in EntityRouteContextBase that I changed to 'entity'. I also added a @throws tag to the getEntityType() method in EntityRouteContextBase. The tests pass on my machine. Patch and interdiff attached.
Comment #46
paulocsPatch #45 looks good.
I really think this issue is important.
Here is the patch re-rolled for 9.1.x-dev.
Comment #48
paulocsNew patch.
Comment #49
evilehk commentedTests pass and the patch and interdiff look good. Setting back to RTBC.
Comment #50
alexpottAre these necessary? A container rebuild will occur when this is shipped in the new minor - the drupal version is part of the container cache key. I think only a container rebuild is necessary here.
Comment #51
paulocsFollow a new patch without code from comment #50.
This was only inserted to refresh cache because it was needed to add an argument in the service definition file, but if
, it makes sense to remove it.
Change to needs review again.
Cheers,
Paulo!
Comment #52
thallesWorks fine to me!
Thanks every one!
Comment #53
alexpottWe still need a change record and a release note snippet as per #42.
Comment #54
paulocsJust created the change record.
See in: https://www.drupal.org/node/3160602
Comment #55
alexpott@paulocs it would be great if the CR could also cover what this change enables.
Comment #56
paulocsHey @alexpott,
I edited the CR and added this line:
Is it enough? If there is any other problem with the English or any suggestion, please let me know.
Cheers,
Paulo.
Comment #57
tim.plunkettNeeded reroll after #2890758: Block visibility node type not working on preview/revision routes landed
Comment #58
ravi.shankar commentedComment #59
ravi.shankar commentedHere I have tried to reroll patch #51.
Comment #60
hctom@ravi.shankar can you please provide an interdiff for the reroll so it is possible to track down the changes? See https://www.drupal.org/documentation/git/interdiff for more information.
Comment #61
paulocsAttached interdiff between patch #51 and #59
Comment #62
hctomHmmm something is strange here. @paulocs: Your interdiff looks broken, check the "--", "+-" etc. at almost all lines. So I tried to create a corrected interdiff and I can't even get one done with the patch from #59.
I'm not really sure what the problem is here, but when I take a quick look at the interdiff from #61, there definitely happened a failure during the reroll:
The "implements" is wrong here, because
NodeRouteContextstill has to extendEntityRouteContextBase.So all in all with the interdiff problems and the reroll failure, I guess it is better to try a completely new reroll of the patch and hide the patch from #59 in the file list.
Comment #63
evilehk commentedAttached is the rerolled patch from #51 and an interdiff. In this reroll, the logic from issue #2890758 was moved from NodeRouteContext to EntityRouteContextBase and modified slightly to be compatible with any entity type. Locally the tests PagePreviewTest and TermContextTest run successfully.
Comment #65
evilehk commentedThis patch resolves the test failures.
Comment #66
hctomI'm totally lost currently with the last 2 patches and their interdiffs ;) My dreditor extension for can not really display them correctly as a nice diff output and so I can't see what changed. Did you create the interdiffs the way it is described at https://www.drupal.org/documentation/git/interdiff ?
Comment #67
evilehk commentedHi hctom. I do reference that page when creating interdiffs. The last section called "What about rerolled patches" recommends just a diff, which is what I did. Perhaps the interdiff between 63 and 65 could have been something other than a diff.
Comment #68
paulocsJust to clarify, the interdiff #61 was just a diff because it was a re-rolled patch.The interdiff between patch #65 and #63 should not be only a diff because they are not re-rolled patch, so it must be an interdiff.
Just attached the interdiff between #63 and #65
Cheers,
Paulo.
Comment #69
berdirThis does make things a bit more generic than they are in reality, node_preview is a node specific feature. I guess it doesn't hurt and is very unlikely to conflict, although in theory it is possibly that someone has a foo_preview entity type where foo also exists.
Note that #2730631: Upcast node and node_revision parameters of node revision routes will change this logic once again in the node context provider.
not sure if passing these arguments through the constructor is really the best option, we could also do abstract methods. That might be easier to handle in the future if we ever have to change the constructor and add ore remove some argument, that could get painful.
the second value could also have a default implementation, because there's a standard pattern for it that the node entity type (currently) doesn't follow.
Comment #70
joseph.olstadPatch applies cleanly to 9.1.x
patch does not apply cleanly to 9.0.x - needs a reroll for 9.0.x
Comment #72
pcambraSetting as NW as per #69, I think this is a good idea but it's taking the feature out of scope for the past 2 patches or so, IMHO there should be a Taxonomy context provider and then a follow up for a centralized entity API context provider, or maybe adding that to entity api first even: https://www.drupal.org/project/entity
Comment #73
berdir-1 on adding it to entity.module first, this isn't just a class that you can deprecate, it's a context identifier that's then in block and other configurations and is painful to update. Similar to the entity condition plugin that is in ctools and I've tried to get into core.
At most, we could add a base class that people have to expose for a specific entity type with a subclass, but not sure that there's much benefit.
Comment #74
sylus commentedI needed a compatible patch for 9.0.x so just attaching a reroll for that branch.
Comment #75
joseph.olstadI haven't followed along here but just fyi, this patch conflicts with :
#2890758-69: Block visibility node type not working on preview/revision routes
Comment #76
joseph.olstadComment #77
sylus commentedYup that patch is pretty important to fix up context_definitions, maybe just adjust your patch to work with it :D
Comment #78
hctomI just read through the comments and to get this issue rolling, I also think we should go back to the "context provider only without a base class" solution in the first step. The base class may make sense in the future, but this is quite an overkill for now and results in many conflicts with other patches.
I will work on this today for the DrupalCon Europe contribution day so we can get moving on.
Comment #79
hctomFirst of all, I created an issue fork that has all the latest changes from patch in comment #65. Additionally I created another issue fork for the "no base class" approach (with changes of patch from #38 applied, which is the latest patch before reworks started towards a base class).
Comment #81
hctomI double-checked the term route context provider code with the node router context code and unified some nitpicks.
2998826-term-route-context--no-base-classbranch now should have all that's needed to get the context provider in (including the tests and merge request). Let's see what the pipelines say...Comment #82
paulocsFor me it looks good.
I tested it creating a condition like
context_definitions = {"taxonomy_term" = @ContextDefinition("entity:taxonomy_term", label = @Translation("Taxonomy Term"))}and integrate it with context module.It is working as expected.
Comment #83
quietone commentedI was wondering what this issue is about and reading the Issue Summary and I am not any wiser. I then looked at the Change Record and that didn't help either. Now, I know that I live in a migration silo so I don't expect to grasp everything. I do find that change records with a before and after example really helpful. If that is possible here, can that be added?
In #53 a release note snippet was asked for and I don't see that in the IS. So, sorry, setting NW for at least that.
Comment #84
hctom@quietone: Good catch - the Change record definitely has to be rewritten, because it still talks about the base class approach. But I think there will be no before/after examples possible, because the functionality provided by this patch just didn't exist before ;)
I updated the issue summary to add a basic release note snippet.
I also cleaned up the issue a little by hiding all patch files, because the issue fork branches already contain all their changes.
Comment #85
hctomComment #86
wongjn commentedEdited the release note; please take a look.
Comment #87
paulocsThe change record looks good.
A release note is different from a change record @Wongjn.
I'm not sure but I think only core maintainers can create a release notes (for drupal core). Please correct me if I'm wrong...
Moving back to RTBC as CR looks good.
Comment #88
wongjn commentedOops, yes that's my bad; Freudian slip!
Comment #89
catchFound a couple of things - see comments on the PR.
Comment #90
hctomRebased the branch and changed the variable name as suggested by catch - just to note: This naming change is also necessary for the node route context, but that should be done in another ticket (if needed).
Comment #91
cdesautels commentedApplied patch #65 to core v.9.1.5. The patch applied, but made no difference. Taxonomy Term context is still not recognized.
Comment #92
hctomPatch #65 is quite outdated. You should use a patch based on the current issue fork.
Comment #93
james.williamsJust to help those of us out that use patches (e.g. with composer), here's a patch file downloaded from the merge request as it currently stands.
Meanwhile, catch's comment has been addressed, so I think it's correct to put this back to RTBC?
Comment #94
catchIdeally I think we would have a plugin derivative that generates these for entity types. However, we don't at the moment, and I couldn't find an issue to have one.
So, I think it is fine for this to go in (caveat I need to review it one more time), but it'd be good to open a follow-up to look at feasibility of using derivatives instead.
Comment #95
paulocsHello @catch,
I tested it integrating the new feature with context module and ctools.
The code and test coverage look good as well.
So RTBC+1 for the
2998826-term-route-context--no-base-classbranch.Comment #97
catchCommitted/pushed to 9.2.x, thanks! (removed the redundant parentheses mentioned above on commit)
Opened the follow-up and tidied up the release note.