Problem
Entity operation links are defined by entity types' list controllers and can be altered using hook_entity_operation_alter()
. However, Drupal core provides no way for modules to declare operation links for entities that are not their own. Because of this, Field UI abuses the alter hook for definitions, which means its operation links can never be altered by modules with a lower weight.
Proposal
#1839516: Introduce entity operation providers aspired to add entity controllers to solve this problem, but the change was deemed too large to be committed to Drupal 8 at this point in the development cycle.
This issue introduces hook_entity_operation()
which is intended to define entity operations links before they are all altered by the existing hook_entity_operation_alter()
.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#87 | drupal_2165725_87.patch | 32.57 KB | Xano |
Comments
Comment #1
XanoComment #2
plachWell, we definitely need something like this at least.
These look weird :)
Comment #3
XanoWhat's weird about it?
Comment #5
dawehnerWe do that kind of style all over the place.
Comment #6
plachYup, sorry, I had a very quick look and didn't notice it was a test.
Comment #7
XanoComment #9
XanoComment #10
joachim CreditAttribution: joachim commentedIt's usually normal for the hook docs to have the specification for the array structure, and the retrieval function to reference the hook docs.
Comment #13
XanoThe problem is actually a bit bigger than I initially thought.
EntityListControllerInterface
only specifiesgetOperations()
, but notbuildOperations()
. As we depend on interfaces, we have to usegetOperations()
, which at this moment does not cause the hooks to be invoked.Comment #14
XanoThis is very likely to break a bunch of things in core, but it does illustrate the problem mentioned in #13. I tried to solve this by moving all hook invocations to the implementation of
EntityListControllerInterface::getOperations()
, and the definitions of default operations toEntityListController::getDefaultOperations()
. If this is okay, we will have to modify all existing list controllers slightly, as most overrides ofgetOperations()
will then become overrides ofgetDefaultOperations()
.Comment #15
damiankloip CreditAttribution: damiankloip commentedYeah, this certainly looks like a more sensible change to me. Why the hell do we have the alter hook in a method that is not a part of the interface? That doesn't really make alot of sense...
+1 to that change in principle.
Comment #16
XanoThis issue is necessary for #2165989: Add a Views field handler for multiple entity operations not to cause WTFs.
Comment #17
XanoAny other feedback before I start converting current
getOperations()
implementations togetDefaultOperations()
?Comment #18
Xano14: drupal_2165725_14.patch queued for re-testing.
Comment #19
XanoTo do:
- use a route name instead of a URL path in the hook_entity_operations() documentation.
- Move the sort to getOperations().
Comment #20
XanoI
hook_entity_operations()
documentation.getOperations()
.getOperations()
togetDefaultOperations()
to make sure controllers' default operations can be altered throughhook_entity_operation_alter()
.Comment #21
joachim CreditAttribution: joachim commentedDoes getOperations() always get all of them?
What if you only wanted to show some of them?
Comment #22
XanoThat's currently impossible (except through
hook_entity_operation_alter()
and some black magic) and beyond the scope of this issue.Comment #23
Xano20: drupal_2165725_20.patch queued for re-testing.
Comment #24
damiankloip CreditAttribution: damiankloip commentedI guess this should not use $this yet? :)
Thank you! This living here was a mistake, for sure.
Shouldn't we assert the actual return value from getOperations() too?
What's going on here? Are we testing with TestEntityListController or EntityListController? :)
This means defaultOperations will always win over the hook declared operations if there is a key clash. Not saying it's wrong, but is that the desired behaviour?
Comment #25
XanoIt refers to the method on the same class and not necessarily to the one on the class the method is called on.
Done.
TestEntityListController
is for the other test methods. This one doesn't need it.I did this on purpose. I don't want people to abuse the info hook as an alter hook just because it happens to work for now.
Comment #26
XanoRe-roll.
Comment #28
XanoComment #30
XanoThere turned about to be a number of unconverted list controllers (thanks @herom!)
Comment #31
herom CreditAttribution: herom commentedI don't see anymore issues with this.
Comment #32
XanoRe-roll........
Comment #33
XanoRe-roll because of field_ui.module.
Comment #34
XanoRe-roll.
Comment #36
XanoComment #38
XanoComment #39
XanoRTBC per #31.
Comment #40
alexpottdrupal_2165725_36.patch no longer applies.
Comment #41
XanoRe-roll and RTBC, as everything applied, except for a tiny bit of documentation.
Comment #42
XanoComment #43
xjmI think this needs probably a change record, and draft change records are now required before commit. Please also search for existing change records that might need updates and link them here (or confirm that there are none). Thanks!
Comment #44
XanoThere is Entity list operations can now be altered. Should I just edit that one (especially because this patch changes the existing alters in core to definitions), or do we indeed want a dedicated change notice as well?
Comment #45
XanoChange record posted at Entity list operations can now be declared by any module.
Comment #46
xjmLooking at the two change records... the new draft at https://drupal.org/node/2198231 looks good, but https://drupal.org/node/2019575 is then a little confusing.
Can we merge the two? I.e., add everything from https://drupal.org/node/2019575 to the new draft at https://drupal.org/node/2198231, and then once this is committed, we can make the new change record live and unpublish the old one. Make sure to add a reference to #2004408: Allow modules to alter the result of EntityListController::getOperations on the new draft as well, I guess. Thanks!
Comment #47
xjmAlso, maybe the bottom section of https://drupal.org/node/1799642 needs an update?
Comment #49
XanoI merged https://drupal.org/node/2019575 into https://drupal.org/node/2198231.
Comment #50
Xano41: drupal_2165725_41.patch queued for re-testing.
Comment #51
XanoRTBC, under the condition that the tests pass.
Comment #53
jibran41: drupal_2165725_41.patch queued for re-testing.
Comment #54
XanoRTBC, as the test failures were caused by a bug in HEAD.
Comment #56
XanoRe-roll because of #2124377: Rename "Picture" module to "Responsive Image" module.
Comment #57
XanoRTBC, under condition that the tests pass.
Comment #58
tstoecklerThe only thing that's worth marking this needs work for is that config_translation_entity_operation_alter() should be re-purposed to config_translation_entity_operation_info().
Also, as I'm writing this I realize the following: Why is this not called hook_entity_operation_info()? I think that would be more consistent.
I also don't really know why #1839516: Introduce entity operation providers was abandoned. I liked that issue a lot more ... :-/
The rest are nitpicks:
Super minor but since we are using keyed arrays, I think something like
would be clearer.
Maybe "An array of operations as ..."
This is not altering but overriding the entire 'translate' operation.
I know that that is not your fault but it is nothing but insane that we have to do this in a "unit" test.
Comment #59
XanoRe-roll because of #2120871: Rename EntityListController to EntityListBuilder, and addressed 1, 2, and 3 from #58.
I disagree. The hook does not expose static data, but in fact acts upon the entity that is passed on.
Comment #61
XanoThere was one direct invocation of
hook_entity_operation_alter()
left, which I just changed to calling the respective list builder instead.Comment #62
tstoecklerThis looks great. Sadly I have one more problem with this, see 2.
So we're introducing a list builder here, but only using it for the operations? Hmm... It's definitely better than calling the hook manually, so yeah. And that's a step in the right direction, because field instances really should be using a *proper* list builder.
I might be missing something but this is not actually testing that the operation that got added is there?
Comment #63
XanoYes, yes, and yes. It's also one of the consequences of not having list controllers or operation plugins.
You were missing a fix! Gladly I had a spare one and added it to the patch.
When I feel sad, I stop being sad and be awesome instead. True Story.
Comment #64
tstoecklerAwesome, looks great!
Comment #65
catchCommitted/pushed to 8.x, thanks!
Comment #68
catchComment #69
XanoThe problem was that field instance configuration entities did not have a list builder that provided operation links. The attached patch adds this.
Comment #70
XanoRe-roll.
Comment #71
XanoNow with test coverage for field instance operations.
Comment #72
fagoUnnecessary new line.
This seems a bit weird, but is a pre-existing condition. Having at least an exception now helps.
Thus, patch looks good and come with test coverage for the previous problem. RTBC again then.
Comment #74
XanoRe-roll, and removed the redundant newline.
Comment #76
Xano74: drupal_2165725_74.patch queued for re-testing.
Comment #78
XanoFixed the failure, renamed FieldInstanceListBuilder to FieldInstanceConfigListBuilder and added an explanation for the exception to FieldInstanceConfigListBuilder::render().
Comment #80
tstoecklerI don't think this works, because the filename doesn't match the class name.
Regardless we should add some tests for this. Since this broke HEAD already that means we are lacking in this area.
Comment #81
XanoThis *has* tests now (see #71), which is partly why the patch from #78 broke.
Comment #82
tstoecklerOops, sorry, I missed that. Looks great!
Comment #84
XanoComment #85
tstoecklerComment #87
XanoRe-roll. The reject was
Comment #88
XanoRTBC if the tests pass.
Comment #90
webchickThis unblocks some other refactoring as well as some contrib stuff, so re-categorizing as a task vs. a feature request, since we're not committing those.
I didn't look at the patch at all, but since catch had already committed it earlier and it was rolled back due to a regression, now fixed + test covered, this seems good to go.
Committed and pushed to 8.x. Thanks!
Comment #91
tim.plunkettFollow-up, patch on the way: #2235347: Field instance operations are out of order