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.
As already realized in the task: https://www.drupal.org/node/2623942.
I am going to implement the same permission logic for the Drupal 8 release of this module.
Comment | File | Size | Author |
---|---|---|---|
#23 | interdiff-2630114-18-23.txt | 573 bytes | jordanpagewhite |
#23 | 2630114-23.patch | 13.31 KB | jordanpagewhite |
#18 | interdiff.txt | 7.59 KB | benjy |
#18 | 2630114-18.patch | 13.31 KB | benjy |
#16 | 2630114-16.patch | 12.22 KB | jordanpagewhite |
Comments
Comment #2
sgurlt CreditAttribution: sgurlt at Bright Solutions GmbH commentedAnd as promised, here is the first version of my patch. :)
I tried to stay as close to the D7 version of it as possible.
Please give it a review and let me know if and how it could be improved.
Comment #3
benjy CreditAttribution: benjy at PreviousNext commentedAwesome, thanks for working on this, feedback below:
We've already loaded the $entity right above and then called $bundle on it, I think we should simply do:
Then we can not check $entity at all below and we'll know that $entity->bundle() isn't going to fail.
All this proves we need more tests though, what happens if you add a test now to view an entity that doesn't exist?
Missing space between the "."
Missing space here too, plus remove the && $entity
Drupal 8 still uses lowercase underscore separated names for local variables. E.g. $entity_types, $content_entity_types.
You could probably use array_filter here, might simplify things.
There should be a method called ->label() here. If you add a comment in PHPStorm in the format /** @var \Path\To\ContentEntityInterface $var_name */ it will allow you to autocomplete them.
Can we use the wording we used in the D7 version? That was one of the things I changed on commit.
Again, i'd expect there to be a ->label() method, if not and this is some kind of translation object? You can just cast it to a string with (string) and handle this is one line.
If you add "use StringTranslationTrait;" inside your class, you'll be able to use $this->t()
Lets add a test to a non-existent entity to catch the problem I mentioned above.
Comment #4
sgurlt CreditAttribution: sgurlt at Bright Solutions GmbH commentedWow, thanks for that great feedback! I think I found the right place to improve my D8 skills :)
I will keep on working on that today.
Comment #5
benjy CreditAttribution: benjy at PreviousNext commentedAny luck with this? Thanks for the work so far.
Comment #6
benjy CreditAttribution: benjy at PreviousNext commentedUn-assigning, going to try roll this into the next release in the next couple of weeks, feel free to pick it back up again if you have time otherwise i'll finish it off.
Comment #7
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commentedI tried to update the patch in #2 using @benjy's suggestions. I'm not sure what's going on with the tests locally. It seems like it might just be an error on my end, maybe something with the permissions. I'll look into it later. Lets see what testbot thinks.
Comment #9
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commentedtrying to fix some of the test errors
Comment #10
benjy CreditAttribution: benjy at PreviousNext commentedThanks for re-rolling this, a few comments to start with, i'll have to give it a proper test.
This needs to be converted to the 8.x version, also need to test it.
Just delete this comment now, no longer part of the coding standards.
Just remove this else, the statement above does a return anyway so no need for the nesting.
Comment #11
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commentedOkay, I made those changes except for testing hook_update_N(). I've never done that before. I'm a newer contributor. I checked the 7.x version of this module and didn't see a comparable test there to try to convert to Drupal 8. Am I missing something or is the test missing in both versions?
Comment #12
benjy CreditAttribution: benjy at PreviousNext commentedWhen I said test it I actually just meant a manual test, that's what i've done previously.
However, upgrade tests are possible in Drupal 8, if you want to have a go the instructions are here: https://www.drupal.org/node/2536494 might take you awhile though so completely fine with me if you'd rather leave it.
Comment #13
benjy CreditAttribution: benjy at PreviousNext commentedThanks for working on this, final review below and then I think we're nearly there.
If we use ContainerInjectionInterface we can inject this.
I think array filter reads better here:
No need to store this in a local variable, just call it inline.
Can we update the descriptions to accurately describe each permission?
Can also inject this.
Again, just inline this.
Maybe we could add an extra test to ensure this user can print the user entity?
Comment #14
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commented@benjy Ah, I understand now. I ran updb locally. It applied cleanly.
Comment #15
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commentedI, somehow, missed until this moment your comment #13. You must have added it as I was adding my comment #14. I will review your comments and make another patch sometime today. Thanks!
Comment #16
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commentedI'm pretty sure that I've incorporated all of your suggestions into this patch. If not, let me know. I wrote a test to check that that a User can print themself and it's passing. I injected what I could. It looks pretty spiffy now. Oh, also, I removed the permissions descriptions for now. I didn't think that the current ones were adding any value that weren't already present in the titles, and I couldn't think of a better set of descriptions. If you have any thoughts, I'd be happy to incorporate them. Thanks as always.
Comment #17
benjy CreditAttribution: benjy at PreviousNext commentedGreat this looks good, i'll try do some manual testing in the next couple of days.
One point:
Do we need to revoke the old permission?
Comment #18
benjy CreditAttribution: benjy at PreviousNext commentedOK, I tested this and we do need to revoke the permission as well, although the config object had numeric keys after the upgrade, need to investigate that.
I fixed up some coding standards and also made a few changes in the access callback to ensure cachability data is maintained. It doesn't actually matter for this module because with PDF's the responses are uncacheable anyway but I think it still makes sense to do it right.
Comment #19
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commentedSounds good. Do you prefer interdiffs on this project? I can include interdiffs in the future. I usually don't include interdiffs on my contrib work because it seems like very few maintainers care for them, as opposed to core maintainers.
Comment #20
benjy CreditAttribution: benjy at PreviousNext commentedOK, it was an issue in core, revokePermission() incorrectly preserves the array keys, not sure if it has any possible side effects but there is already an issue #2409129: Enforce order of permissions in config export
Comment #21
benjy CreditAttribution: benjy at PreviousNext commented@jordanpagewhite it's just a habit i've gotten into working on core so much, interdiffs are handy when you have a big patch and you only want to review the difference. Doesn't matter so much here because most patches are small :)
If you're happy with my recent changes, i'll commit this tomorrow.
Comment #22
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commented@benjy I only had a very brief look at it because I'm at work, but from that brief scan, it looks good to me. If you happen to have a second to explain what you did with the dependency injection of \Drupal\Core\StringTranslation\TranslationManager, I would be really interested in that. Thanks again for taking the time to work through this one with me. The permissions will be great, and the file looks nice now.
If I have a moment this evening, I will download your latest patch and make sure that everything applies cleanly.
Comment #23
jordanpagewhite CreditAttribution: jordanpagewhite as a volunteer commentedLooks good! It applied cleanly. I fixed a typo in a comment.
Comment #25
benjy CreditAttribution: benjy at PreviousNext commentedCommitted and pushed, thanks.