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.
When recreating a feature containing a flag for an entity where the flag definition is provided by the flag_flag_definitions_alter hook in flag.inc, I get the following error when opening the "Recreate" page of Features:
"Notice: Undefined index: taxonomy_term in flag_features_export() (line 22 of ...modules/contrib/flag/includes/flag.features.inc)"
The error is thrown because flag_features_providing_module() in flag.features.inc does not take the flag_definitions_alter hook into account when mapping the flag types to modules.
Comment | File | Size | Author |
---|---|---|---|
#8 | flag-features_export-1971980-8.patch | 700 bytes | Volx |
#4 | flag-features_export-1971980-4.patch | 657 bytes | Volx |
#3 | flag-features_export-1971980-3.patch | 577 bytes | Volx |
#2 | flag-features_export-1971980-2.patch | 581 bytes | Volx |
Comments
Comment #1
joachim CreditAttribution: joachim commentedThanks for reporting this.
Will probably need fixing on 3.x first.
Comment #2
Volx CreditAttribution: Volx commentedI finally got around to fixing this problem. Actually Flag is using its own hook wrongly. Per flag.api.php hook_flag_definitions_alter should be used to alter flag definitions provided by other modules, but flag_flag_definitions_alter actually adds _new_ definitions. If the alter hook would be allowed to add definitions, determining what module actually provides a definition is overly complicated. So flag should add flag definitions for entities not already provided for, not in the alter hook but in flag_fetch_definitions.
So assuming that flag is the only module adding definitions outside of hook_flag_definitions, we can simply check for any entities that have not been provided for and safely assume that Flag is the providing module. That is what the patch below does.
The patch applies to 7.x-2.0. A patch for 7.x-3.x-dev will follow.
Comment #3
Volx CreditAttribution: Volx commentedThere is a small error in the patch above, here is a better one.
Comment #4
Volx CreditAttribution: Volx commentedAnd here is the proposed patch for 3.x-dev. For the problem mentioned above, I created a new minor issue here #2070187: Fix misuse of hook_flag_type_info_alter.
Comment #5
joachim CreditAttribution: joachim commentedUrgh, that bit of flag always makes my head hurt. I just had to go remind myself why flag_features_providing_module() can't just call flag_fetch_definition()!
Comment #6
joachim CreditAttribution: joachim commentedDoes it matter that vocabs aren't flaggable?
(If you need to reroll for this, can you also wrap the comment to 80 lines please?)
Comment #7
joachim CreditAttribution: joachim commentedTagging as 3.1 blocker.
Comment #8
Volx CreditAttribution: Volx commentedI already exclude 'taxonomy_vocabulary'
But I fixed the comment length.
Comment #9
joachim CreditAttribution: joachim commentedCommitted, with a tweak to the comment wrapping.
Thanks for all your work on this.
git commit -m "Issue #1971980 by Volx: Fixed Features export not taking into account provision of flag types by flag_definition_alter()." --author="Volx "
Comment #10
japerryIs it possible to get this backported and committed to Flag 2.x ?
Comment #11
joachim CreditAttribution: joachim commentedIf someone provides a patch, and it gets reviewed, I'll commit it.
Comment #12
japerrythe patch in #3 fixed the error for me on flag 2.x
Comment #13
japerrysee #12 and #3 for patching flag 2.x
Comment #14
joachim CreditAttribution: joachim commentedCherry-picked. Thanks for testing!