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.

Files: 
CommentFileSizeAuthor
#8 flag-features_export-1971980-8.patch700 bytesVolx
PASSED: [[SimpleTest]]: [MySQL] 266 pass(es).
[ View ]
#4 flag-features_export-1971980-4.patch657 bytesVolx
PASSED: [[SimpleTest]]: [MySQL] 266 pass(es).
[ View ]
#3 flag-features_export-1971980-3.patch577 bytesVolx
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch flag-features_export-1971980-3.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#2 flag-features_export-1971980-2.patch581 bytesVolx
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch flag-features_export-1971980-2.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Version:7.x-2.0» 7.x-3.x-dev

Thanks for reporting this.

Will probably need fixing on 3.x first.

StatusFileSize
new581 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch flag-features_export-1971980-2.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

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

StatusFileSize
new577 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch flag-features_export-1971980-3.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

There is a small error in the patch above, here is a better one.

Status:Active» Needs review
StatusFileSize
new657 bytes
PASSED: [[SimpleTest]]: [MySQL] 266 pass(es).
[ View ]

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

Urgh, 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()!

Does it matter that vocabs aren't flaggable?

      // We deliberately exclude taxonomy vocabularies from the list of
      // supported entity types because they aren't fieldable or directly
      // viewable, which makes them impossible to flag.
      if ($entity_type === 'taxonomy_vocabulary') {
        continue;
      }

(If you need to reroll for this, can you also wrap the comment to 80 lines please?)

Issue tags:+3.1 blocker

Tagging as 3.1 blocker.

StatusFileSize
new700 bytes
PASSED: [[SimpleTest]]: [MySQL] 266 pass(es).
[ View ]

I already exclude 'taxonomy_vocabulary'

<?php
if (!isset($modules[$entity_type]) && empty($entity['configuration']) && $entity_type !== 'taxonomy_vocabulary') {
 
$modules[$entity_type] = 'flag';
}
?>

But I fixed the comment length.

Status:Needs review» Fixed

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

Is it possible to get this backported and committed to Flag 2.x ?

Issue tags:-3.1 blocker

If someone provides a patch, and it gets reviewed, I'll commit it.

the patch in #3 fixed the error for me on flag 2.x

Status:Fixed» Patch (to be ported)

see #12 and #3 for patching flag 2.x

Version:7.x-3.x-dev» 7.x-2.x-dev
Status:Patch (to be ported)» Fixed

Cherry-picked. Thanks for testing!

Status:Fixed» Closed (fixed)

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