Updated: Comment #23
Problem/Motivation
function hook_entity_operation_alter(array &$operations, \Drupal\Core\Entity\EntityInterface $entity) {}
was added in
#2004408-34: Allow modules to alter the result of EntityListController::getOperations
(there were some followups for random fails, so the history there is a bit confusing)
That hook was useful in #2004428: Less ugly operations altering
But, the hook did not effect some of the entities, blocks was one of the ones the hook did not effect.
See #17-#24 in #2004428-17: Less ugly operations altering
Proposed resolution
Make the hook work for blocks by implementing getOperations() in blocks and using buildOperations().
Add tests for blocks in block. It is the concern of blocks to test it's own stuff.
Remaining tasks
- none
User interface changes
No.
API changes
No.
Blocking
Related Issues
- #2031591: Add a generic Entity test for the hook_entity_operation_alter() that can be reused by each entity
- #2019647: Use EntityListController for menus
- #2004408: Allow modules to alter the result of EntityListController::getOperations
- #2004428: Less ugly operations altering
- #2023743: views: hook_entity_operation_alter() does not work with EntityListController
- #2023739: menu: hook_entity_operation_alter() does not work with EntityListController
Comment | File | Size | Author |
---|---|---|---|
#29 | interdiff.txt | 1.51 KB | penyaskito |
#29 | drupal8.block-module.2027857-29.only-test.patch | 1.91 KB | penyaskito |
#29 | drupal8.block-module.2027857-29.patch | 4.14 KB | penyaskito |
#21 | drupal8.block-module.2027857-21-testonly.patch | 1.91 KB | YesCT |
#21 | drupal8.block-module.2027857-21.patch | 4.17 KB | YesCT |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedoops a bit of confusion between the similar issues.
Comment #2
kfritscheThis needs to be fixed in Core.
$this->buildOperations($entity)
must be used to create the operations array in the Block List Controller. Also the buildRow() method should be used if possible and call parent.Comment #3
YesCT CreditAttribution: YesCT commentednoticed some things while working on this and menu issue.
build -> built
also the hook function needs to use *this* module name,
and we need to enable the test module so the hook has effect.
we expect this to fail, because of #2
ready for review.
Comment #4
YesCT CreditAttribution: YesCT commentedforgot the patch.
Comment #5
kfritscheBlockListController is using now buildOperations() so this should go green.
Don't know if we really need buildRow() here as the rows are grouped by region which makes it more complicated to use buildRow() here. Any comments about appreciated. But the main problem of the issue should be fixed with the patch.
Comment #6
tim.plunkettI agree there is no need for buildRow().
This should use $entity->uri(), see the other list controllers.
Do we really need to implement this for each one? Can't it just enable all of the config entities and test them?
Also this is misnamed, the _hook_ can't be in there.
And the EntityInterface should be `use`'d.
Comment #7
YesCT CreditAttribution: YesCT commented@tim.plunkett Thanks. OK. dont use hook in a name. I'll remember. :)
Don't we only "use" something if it's used more than once?
Maybe I'm reading this wrong:
https://drupal.org/node/1353118
Should we move the test module to the entity module?
Also, I've only made issues to add tests for menu, views, blocks..
are you suggesting we duplicate all the tests from config_translation?
http://drupalcode.org/project/config_translation.git/tree/HEAD:/lib/Drup...
Most are in one file, but views is in separate.
http://drupalcode.org/project/config_translation.git/blob/HEAD:/lib/Drup...
http://drupalcode.org/project/config_translation.git/blob/HEAD:/lib/Drup...
Comment #8
kfritscheNew patch which uses the $entity->uri() now.
Concerning the tests, I found a already existing test for the entity operation in the system module.
I moved the block test code there and also added the tests for the other entity operations.
So everything is there now. More or less its the same as in config_translation.
I think its much better in this way now.
Comment #9
kfritscheComment #10
YesCT CreditAttribution: YesCT commentedI'll test this and review it now. :)
Comment #11
YesCT CreditAttribution: YesCT commentedA. The fix looks good.
B. This looks really great. :) Good location for the tests.
Is changing from a web_user with fewer permissions to an admin user with more permissions removing some test that was here before or changing what it was testing before?
Answering my own question:
oh, I think this test was only doing the foreach role on the roles page, so it's ok here to just use the admin user like it is.
changing the comment to refer to test_operation pushes this over 80 chars.
And in some other places.
Mmm. The old test here was looking for the test_operation of "each" role. But we are not sure there were any.
The new test is just looking for the link on one role.
Is it worth merging the approaches? Making a test role, and then *also* doing a foreach?
I could see some strange bug one day that might do something like only the first item in the list gets the operation added.
Maybe we should make a few test things, and do the foreach. Is it worth it to do that? (I did not do that.)
heh. This used to make sense when it was "Test if the link to translation the vocab..." Fixed.
This is I think left over from when we had all the tests in one giant function and we had section headers. Also, it's not a sentence. I think with the nice functions this is not needed anymore. Taking it out.
missing newline. added it.
oh, also when the method for the views got pasted in, the newline before the last } on the class was lost. I put the newline back in.
Comment #12
Gábor HojtsyI think all of the roles should have a translate tab/link, at least all those already in core. If you add a new one, if you have more than one language, it should also show up proper.
Comment #13
Gábor HojtsyAll right, so I got the scoop on this. We are altering in the operation and the prior tests only tested roles but tested all of them. The new tests test a lot more things, but it would be a pain if they would test all the items on all the pages.
This badly needs an issue summary update, but otherwise amazing. So not yet RTBC unfortunately :/
Comment #14
Gábor HojtsyIn other words, the alter works the same way on all rows. Testing all rows on all entity list items sounds like *overkill*, it does not seem like we would gain something out of that, so the patch looks good not to test all lines in all lists :)
Comment #15
YesCT CreditAttribution: YesCT commentedupdated the issue summary and marked #2023739: menu: hook_entity_operation_alter() does not work with EntityListController as a duplicate of this issue.
Comment #16
Gábor HojtsyYay, thanks!
Comment #17
tstoecklerThe added tag looks like a cross-post.
Comment #18
alexpottNeeds to be protected
I know that this is a duplicate test... there is a high chance we are introducing duplicate tests here. This issue should just fix the block operation alterability. Everything else is scope creep... sorry.
Comment #19
YesCT CreditAttribution: YesCT commentedOK.
So we will just do the test for blocks here, (and not use the doPattern here).
We will make the do... tests protected in config_translation where we use this same pattern.
Regarding
We talked about this, and since it is testing the addition of a link added by the alter, it's not actually a duplicate. :)
I'll work on this.
--------
After this issue, we should make a generic test that can be extended instead of putting a separate independent test in each place.
Once we do that, then we can use *that* in config_translation also.
Comment #20
YesCT CreditAttribution: YesCT commentedComment #21
YesCT CreditAttribution: YesCT commentedI went back to #5 (aka 6). And redid the fixes asked for after that.
Comment #22
kfritscheTested it manually with the config_translation module with ugly form_alters removed. Translate link shows up in block structure. So this works.
Also locally the Test passed for me.
RTBC if testbot agrees.
Comment #23
YesCT CreditAttribution: YesCT commentedupdating title as we have changed back to original strategy of just testing blocks.
I'll update the issue summary.
Comment #23.0
YesCT CreditAttribution: YesCT commentedUpdated issue summary.
Comment #23.1
YesCT CreditAttribution: YesCT commentedadded the issue to make tests generic
Comment #23.2
YesCT CreditAttribution: YesCT commentedadded some fancy 'concern of' words.
Comment #24
YesCT CreditAttribution: YesCT commentedThis issue was RTBC and passing tests on July 1, the beginning of API freeze.
Comment #25
YesCT CreditAttribution: YesCT commented#21: drupal8.block-module.2027857-21.patch queued for re-testing.
Comment #25.0
YesCT CreditAttribution: YesCT commentedupdating comment number that it's updated as.
Comment #26
YesCT CreditAttribution: YesCT commented#21: drupal8.block-module.2027857-21.patch queued for re-testing.
Comment #27
YesCT CreditAttribution: YesCT commentedThis does not apply anymore.
Maybe because #1981144: Convert block_admin_edit() in block.admin.inc to the new form interface got it.
Comment #28
YesCT CreditAttribution: YesCT commentedtag!
Comment #29
penyaskitointerdiff is a diff between patches.
Comment #30
Gábor HojtsyLooks good, back to RTBC assuming it passes.
Comment #31
alexpottCommitted dfee120 and pushed to 8.x. Thanks!
Comment #32
Gábor HojtsyYay, thanks!
Comment #33.0
(not verified) CreditAttribution: commentedblocking config translation in core, via the need to remove the ugly alter.