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
The UserFlagType plugin provides a "Users may flag themselves" option. By default, this option is selected. Clearing the checkbox and saving the flag has no effect.
Proposed resolution
Determine why the option cannot be cleared. Write user flag tests to test the user flag type including the flag-self option.
Remaining tasks
- Write patch.
- Write tests.
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#25 | intediff-24-25.txt | 2.63 KB | martin107 |
#25 | userFlagThemselves.25.patch | 4.41 KB | martin107 |
| |||
#24 | userFlagThemselves.24.patch | 4.29 KB | martin107 |
| |||
#22 | userFlagThemselves.22.patch | 5.29 KB | socketwench |
| |||
#16 | 2409891.16.usersFlagThemselves.patch | 5.83 KB | socketwench |
Comments
Comment #1
socketwench CreditAttribution: socketwench commentedThis might be due to the form default value not being set correctly:
'#default_value' => $this->getAccessUidSetting() ? 0 : 1
Will always default to "true", even when the underlying setting is '0'. Removing the conditional will likely be sufficient, but this highlights the fact there are no tests written for the user flag type.
Comment #2
joachim CreditAttribution: joachim commented> '#default_value' => $this->getAccessUidSetting() ? 0 : 1
That seems weird anyway! The method returns you a bool, so why then set a 0 or 1?
Comment #3
lokapujyadoesn't seem to work with the category. Will have to look into it more, to know why.
Comment #4
lokapujyaComment #5
lokapujyaComment #6
lokapujyaTest for just the bug. I copied and edited doCreateFlag to create a "User Flag". The class doesn't currently need $nodeType, but may utilize it for other tests.
Comment #8
socketwench CreditAttribution: socketwench commentedThe test only tests the checkbox operation, not if the users are able to flag themselves. Here's an update.
Comment #9
socketwench CreditAttribution: socketwench commentedComment #12
lokapujyawe need to change
in 2 places.
Comment #13
socketwench CreditAttribution: socketwench commentedComment #15
socketwench CreditAttribution: socketwench commentedIt looks like the flag link never gets rendered for the user entities because of the following line in flag_entity_view():
While showAsField() returns true, there's no component in $display for the flag. Thus, the link never gets rendered.
Comment #16
socketwench CreditAttribution: socketwench commentedAnd getComponent() returns false because of this line in flag_entity_extra_field_info():
Since the user entity type has no bundle, the value of '0' is used instead of the correct bundle type: 'user'. See user_entity_extra_field_info().
Comment #18
socketwench CreditAttribution: socketwench commentedHm. We're almost there, but we're not actually using the acces_uid setting on the user flag subtype anywhere other than to power a checkbox. While we could make a one-off in flag_entity_view(), that's not an expandable solution.
What could work is to allow flag subtype plugins to have a say in Flag::hasActionAccess(). That way, the plugin can allow or ignore operations as it sees fit.
A further extension to this would be to give subtypes the power to define permissions via Flag::getPermissions(), which could go down the inheritance chain to provide the basic "flag" and "unflag".
Comment #19
BerdirThis looks a bit strange, surprised that this actually works, so we store a list with an empty entry for entity types that have no bundles?
At least the API does fall back to entity_type as the only bundle by default, so I'm not sure how you end up with this result?
If that is really expected, then we should have a method on $flag that abstracts this logic somehow?
Comment #20
socketwench CreditAttribution: socketwench commented$types and $entity_type really should be behind a accessor. Without it, FlagInterface isn't really complete. Then we can add logic for the $entity_type as the only bundle by default.
Comment #21
joachim CreditAttribution: joachim commented> Then we can add logic for the $entity_type as the only bundle by default.
On D7 at least, entity_get_info() does that for us. I don't remember offhand the D8 equivalent to look it up.
Comment #22
socketwench CreditAttribution: socketwench at FFW commentedMore than can't be set, doesn't work period. This fixes that, but it requires the patch from #2711093: Remove auto-set of bundles from FlagTestBase.
Comment #23
martin107 CreditAttribution: martin107 commentedI am looking at this now.
Comment #24
martin107 CreditAttribution: martin107 commentedTo easy the review process I am limiting this patch to a reroll.. after an overnight commit spree.
Looking at the patch it has had the effect as stripping out the changes that were split off into :-
#2711093: Remove auto-set of bundles from FlagTestBase
Comment #25
martin107 CreditAttribution: martin107 commentedThe Review.
I think actually making use of the access_uid configuration option is a good idea. :)
The implementation fixes are good. The integration test picks up the bug +1
So I think this should go in...
Changes
My changes are minor nits and a method name change.
1) t() becomes $this->t()
I have heard the argument that $this->t() is not needed in tests. I think differently - the test are their own program and so I still want to pull t() from a well defined namespace and not global state.
2) testUserFlag was just a wrapper for doPluginUI so I removed one layer of function calls and came up with a new name that was more meaningful to me. Please feel free to object.
3) I added annotations for the test, just to ease the next reader into what is going on.
4) The rest is just trivial nits and what is picked up by phpcs.
Comment #27
socketwench CreditAttribution: socketwench at FFW commentedThanks for the fixes, Martin!