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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

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

Thanks for reporting this.

Will probably need fixing on 3.x first.

Volx’s picture

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.

Volx’s picture

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

Volx’s picture

Status: Active » Needs review
FileSize
657 bytes

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.

joachim’s picture

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

joachim’s picture

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?)

joachim’s picture

Issue tags: +3.1 blocker

Tagging as 3.1 blocker.

Volx’s picture

I already exclude 'taxonomy_vocabulary'

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

But I fixed the comment length.

joachim’s picture

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 "

japerry’s picture

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

joachim’s picture

Issue tags: -3.1 blocker

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

japerry’s picture

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

japerry’s picture

Status: Fixed » Patch (to be ported)

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

joachim’s picture

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.