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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thsutton’s picture

Attached 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.

thsutton’s picture

Status: Active » Needs review
joachim’s picture

Status: Needs review » Needs work

Thanks 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:

$applicable_bundles = $flag->types;
if (empty($applicable_bundles)) {
 // get the list form entity_get_info()
}

thsutton’s picture

I 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.

thsutton’s picture

Status: Needs work » Needs review

Oh self, why do you always forget to update the status?

joachim’s picture

Status: Needs review » Fixed

Committed, 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
"

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Add some steps to reproduce.