Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Entity operations for terms are hardcoded in taxonomy terms's overview page; add or alter operations is impossible.
Proposed resolution
Introduce a taxonomy term list builder that provides the operations and invokes all existing hooks for other modules to alter the operations or provide custom ones. See #3 and #4 for why we need a list builder.
Remaining tasks
Make a patch.
User interface changes
none.
API changes
none.
Beta phase evaluation
Issue category | Bug |
---|---|
Issue priority | Normal, because no data loss or seriously broken features. |
Comment | File | Size | Author |
---|---|---|---|
#51 | entity-operation-2469567-51.patch | 734 bytes | josmera01 |
#47 | 2469567-47.patch | 5 KB | farald |
#43 | interdiff-7-to-43.txt | 537 bytes | claudiu.cristea |
#43 | 2469567-43.patch | 5.07 KB | claudiu.cristea |
Comments
Comment #1
willzyx CreditAttribution: willzyx commentedComment #2
XanoWe use a new approach for this in Drupal 8. All entity operations should be provided by the entity type's list builder (which primarily builds entity listings). The list builders allow entity types to provide their own operations, but also invoke the hooks that are necessary for other modules to provide additional operations. The prime example of that in core are probably the content and config translation modules.
Because term listings are more complex–they cannot be listed all at once, but only per vocabulary–we can only use the term list builder for providing operations. We've done this in core once before (I cannot remember where exactly right now).
Comment #3
willzyx CreditAttribution: willzyx commentedI cannot find another point in which the list builder is used in this way in core.. and doing so dont we lose the destination?
Comment #4
XanoIt's been done before somewhere in a core issue (I remember discussing it with @sun). The reason is that operations handlers could no longer be added to core after code freeze. This is why list builders have become responsible for providing operations links, even though they cannot always provide lists too.
This patch adds destinations.
Comment #5
willzyx CreditAttribution: willzyx commentedcall parent::__construct() instead of set manually the member variables and change
::getOperations
to::getDefaultOperations
.Furthemore in
::render()
\LogicException
is more appropriate, isn't it?Comment #6
XanoDuh... Thanks!
It's all potatoes potatoes to me. I looked it up and
\LogicException
makes sense indeed.This change is actually a regression, as it would override any existing GET parameters and we don't want that.
Comment #7
willzyx CreditAttribution: willzyx commentedlooking at EntityListBuilder::getDefaultOperations() this should not be a problem. however..
Comment #8
XanoThanks!
It's unlikely, but the way your patch from #7 does it, is better practice. Basically: don't touch anything you don't have to.
Comment #9
XanoThanks!
It's unlikely, but the way your patch from #7 does it, is better practice. Basically: don't touch anything you don't have to.
Comment #10
willzyx CreditAttribution: willzyx commentedI think we should create, in a similar manner, a patch for shortcuts (links list page)
Comment #12
miro_dietikerWe tried to implement hook_entity_operation_alter() for all entity types in collect contrib and it was not possible to alter tag operations. See #2491307: Add "Capture" operation to all content entities
Works like a charm after applying this patch.
Comment #13
andypostAny reason to introduce non-usable list bulder?
Suppose proper fix is to convert OverviewTerms to list builder
incredible hack...
Comment #14
XanoSee #3 and #4 for why this is done in such a 'hacky' way. In 2014 the decision was made that because of code freeze we could no longer add new entity type handlers. The entire page cannot be converted to a list builder easily or at all, because the page only displays terms for a specific vocabulary, whereas list builders were designed to display all entities of a specified type.
Comment #16
miro_dietikerLooks much RTBC to me. (edited) Except: There is no documentation at all that explains why the TermListBuilder is limited to operations only.
Comment #18
XanoDoes this mean there is or is not enough documentation?
If there is, do you see any other objections to an RTBC?
Comment #23
miro_dietikerI'm not used to documentation verbosity in core.
There is zero explanation on why. I would have expected to see some comment similar to your words above:
Comment #24
XanoThe technical reason is that we crammed two separate features (list building and operations) in the same interface (
ListBuilderInterface
) and we shouldn't have. There are numerous reasons why classes wouldn't want to provide lists, but do provide operations.In practice, the only reason I have seen so far (IIRC) is that we use alternative listing methods. I'm not sure we should explain this in the exception message, as the choice to use these alternative methods lies with the application (the entity type definition) and not with the list builder itself.
However, based on that reasoning, we should perhaps allow lists to be made using this list builder in case someone wants a list of terms across all vocabularies. It would also mean the class complies with the interface and there are no WTFs about application-level decisions.
Thanks for pointing out we can and should improve documentation!
Comment #25
ArlaWhy is the destination param expected for term operations but not for operations of other entity types? Should we consider adding destination param to (some) operations in EntityListBuilder?
Comment #26
gappleRan into a similar issue with menu links, so created #2684577: Entity operations for menu links are hardcoded in edit menu form with some changes based on this issue.
Comment #27
miro_dietikerHm i guess it would be 8.x-2.x target meanwhile?
Comment #28
gappleRe-roll for 8.2.x
Comment #30
ArlaDid a little bit of digging to answer #25, and found that both term and node operations have been including the destination for a long time. I guess there's no point in trying to change that in this issue.
Comment #32
effulgentsia CreditAttribution: effulgentsia at Acquia commentedI queued a retest of #28 (on 8.3.x) to see if anything's changed in 6 months.
Comment #33
effulgentsia CreditAttribution: effulgentsia at Acquia commentedCool. Same two failures. Anyone here able to debug them?
Comment #34
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at Axelerant for Red Hat commented@effulgentsia i am on it.
Comment #35
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at Axelerant for Red Hat commentedComment #36
andypostthis change is wrong! edit forum always have params!
Comment #37
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at Axelerant for Red Hat commented@andypost i tried to replicate it.
However exception is at the same line. [Notice] Line 64 of core/modules/forum/src/Form/Overview.php
Tried to reproduce by running test case locally as well.
Can there be anything that is internally calling `Overview.php` of forum module ?
Comment #38
Berdir#2767857: Add destination to edit, delete, enable, disable links in entity list builders does this in a generic way, then we wouldn't need this anymore.
not sure why we need to do this.
Comment #39
BerdirNot sure if/why that is needed with the forum operations but what about moving that to hook_entity_operations_alter() and out of the custom controller?
Comment #40
effulgentsia CreditAttribution: effulgentsia at Acquia commentedBut that issue sets the destination to the 'collection' link template. Which wouldn't work for taxonomy terms, since they don't have such a template, and if we wanted to add such a template, it would need to have the
{taxonomy_vocabulary}
parameter. I guess we could do that by adding aTerm::urlRouteParameters()
override?Comment #41
BerdirYeah, but as I commented there, I think that is wrong anyway and we should use the redirect destination API which defaults to the current page. See also #2838968: BlockContentListBuilder should use RedirectDestinationTrait instead of hardcoding the collection link template, any view that displays operation links would have the same problem as term.
Comment #42
effulgentsia CreditAttribution: effulgentsia at Acquia commentedComment #43
claudiu.cristeaThis is a bug and should go to 8.2.x. I rerolled #7, that was the last good.
@Berdir,
That is a 8.3.x issue and that should account this fix if this will go first. Or we fix here if that goes first.
Removed
render()
hack.Comment #46
andypostComment #47
farald CreditAttribution: farald commentedRe-roll against 8.3.x.
Tests are probably still failing though.
Comment #48
miro_dietikerComment #50
BerdirI posted a detailed overview of all related issues that we have around this topic in #1848686-179: Add a dedicated permission to access the term overview page (without 'administer taxonomy' permission) (#179 if the link does not work).
As suggested there, I'm closing this issue as a duplicate of that issue as that also has to solve this problem.
I'll try to update that other issue and possibly incorporate the approach that this issue uses with the list builder.
Comment #51
josmera01 CreditAttribution: josmera01 at Globant commentedAdd the patch for the version Drupal 8.3