Entities like `user` don't have any bundles so `$flag->types` is empty. The `flag_field_extra_fields()` function assumes that `$flag->types` is non-empty and does nothing for these flags. This means that flags on these entities cannot be displayed correctly as a field for these entities.
Either the flag instance classes should be updated to ensure that `$flag->types` is not empty in these cases or `flag_field_extra_fields()` should be updated to handle the empty case correctly.
Steps to reproduce:
1. Install Drupal and the Flag module.
2. Create a new user flag. Enable "Users may flag themselves" and "Display link as field". Disable other "display" options.
3. Visit admin/config/people/accounts/display and notice that there is no entry for the flag.
4. Apply the patch, clear caches and see the flag is now present on admin/config/people/accounts/display.
Comment | File | Size | Author |
---|---|---|---|
#4 | 2100845-4-flag-as-field-with-no-bundles.patch | 645 bytes | thsutton |
#1 | 2100845-1-flag-as-field-with-no-bundles.patch | 407 bytes | thsutton |
Comments
Comment #1
thsutton CreditAttribution: thsutton commentedAttached is a patch which changes `flag_field_extra_fields()` to handle the empty case. It seems to work in my test for the `user` case.
Comment #2
thsutton CreditAttribution: thsutton commentedComment #3
joachim CreditAttribution: joachim commentedThanks for reporting and for the patch.
However, the approach isn't quite right. If $flag->types is empty, it means all bundles apply.
Hence we probably need to do something like:
Comment #4
thsutton CreditAttribution: thsutton commentedI originally thought that this functionality probably belongs in the flag_entity class/subclasses, but couldn't be bothered figuring out where.
Here's an updated patch for this single use site.
Comment #5
thsutton CreditAttribution: thsutton commentedOh self, why do you always forget to update the status?
Comment #6
joachim CreditAttribution: joachim commentedCommitted, with a comment added to explain the empty bundle list option.
Thanks!
git commit -m "Issue #2100845 by thsutton: Fixed flag pseudofield not appearing for flags which have an empty bundle list to signify all bundles." --author="thsutton
"
Comment #7.0
(not verified) CreditAttribution: commentedAdd some steps to reproduce.