I'm writing a module (currently in sandbox) that uses flags defining the required ones in hook_flag_default_flags().

How do I disable a flag when I disable the module and delete them (hence, loosing all its associated data) when I uninstall the module?


joachim’s picture

IIRC you'll find methods for those on the $flag object -- there is definitely a $flag->delete(), and there is surely a way to disable them too, as flags that are from an older version of the API get disabled.

sylvaticus’s picture

I have tried $flag->disable() in hook_disable() but it didn't work. Even bad I noticed that if the site admin delete a flag in the UI than the flag module "keep memory" of it and it doesn't allow the flag to be recreated by the consumer module, even if this one is disabled/uninstalled and re-enabled.
So for the time been I just let the users to create and manage the flag(s) by themselves and ask for their name in the consumer module settings, but if there is a workflow for flag consumer modules to define them in code, create them when the module is enabled, disable them when the module is disabled and cancel them when the module is cancelled, avoiding users to be able to cancel them in the ui (like for the other 'locked' flag settings) I would be more than happy to avoid users to have to define the flag settings by themselves.. Is there any flag module that can be used as best-practice for it? (the bookmark module just define them in hook_enable())

joachim’s picture

> I have tried $flag->disable() in hook_disable() but it didn't work

It looks like whether a flag is disabled is stored in a variable, flag_default_flag_status. Which is a little odd.

But that still should work -- flag_get_default_flags() takes it into account when loading flags.