Closed (fixed)
Project:
Flag
Version:
7.x-3.0-alpha4
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
18 Mar 2013 at 14:07 UTC
Updated:
29 Apr 2015 at 21:34 UTC
Jump to comment: Most recent
Comments
Comment #1
joachim commentedIt's doable, in that Flag exposes hooks allowing custom code to check and decide whether to allow a flagging to happen.
You'd need to write custom code to do this though.
Comment #2
tds2012 commentedThanks for your reply. Never wrote custom code before, just customized existing code/modules. Where and how should I begin?
Comment #3
joachim commentedGosh. Welcome to coding :)
You'll need to start off by reading up about how to write custom modules and how to use hooks. Lots of tutorials around.
Then, read up on Flag hooks: they are documented in the module's api.php file. You want IIRC hook_flag_validate(), which is probably only on 3.x.
Then implement that, and start experimenting :)
Comment #4
joachim commentedCan you try this with the latest 3.x code please?
The code to convert flag permissions to user permissions has a few awkward things to work around, but I'm tried an upgrade several times and it's worked fine for me.
Comment #5
tds2012 commentedI tried with 7.x-3.x-dev, but when I select the existing flag on the comment, it throws a PDOexception though permissions and so on are correct I think:
when trying to make a new flag on comments, it gives the same error (or similar pdoexc.)
Now installed 7.x-3.alpha4 and the error notice is gone. But ...
how can I now limit flagging to only 1 flag? I don't see any option. Except ..;
unfortunately i only see hook_flag_validate in the dev-release.
suppose I can use this hook (can I just copy it from the flag.api of alpha4 to the flag.api of the dev-release?) and setting the count to 1. Is that allowing only 1 flag on that specific node or only 1 flag on any node throughout the site?
Comment #6
tds2012 commentedany more advice?
regards
tommy
Comment #7
joachim commented> the flag.api of alpha4 to the flag.api of the dev-release
api.php files are never loaded or executed, they are documentation, as should be stated at the top of it.
> unfortunately i only see hook_flag_validate in the dev-release.
I should make a new release soon... but I am waiting on a couple of blockers.
That's checking flags on all nodes -- read the comments!
Comment #8
anybodyThis issue is still open. Does someone know if there is a module for this yet or a general solution?
What we need is:
- Hide other flag buttons if there is one comment flagged per entity
- Validation
Thank you very much!
Comment #9
joachim commented> I want that user to flag only 1 comment.
It actually sounds like this is an 'accepted answer' type of functionality. There's a module for that!
Comment #10
anybody@joachim: Thanks a lot. Could you please provide the link to the module to help me and others with this problem?
Comment #11
joachim commentedI don't remember the name. Google it! :)
Comment #12
anybodyYou can be sure I did that before...
flag_limiter.module is the only one I found that might nearly match the "Accept answer" functionality.
https://www.drupal.org/project/flag_solved is good but is not compatible with the latest Flag module.
If you say there's a module for that please always link the module in the future if possible, otherwise that answer isn't helpful for the community, I think. Thank you anyway.
Comment #13
joachim commentedhttps://www.drupal.org/project/best_answer
Comment #14
anybodyThank you very much. That's really nice.
I'll also keep this issue updated if I find another solution that's based on flags.
Comment #15
anybodyMy final results:
https://www.drupal.org/project/flag_solved is the best Flag based solution to mark a single comment as accepted / best answer.
Sadly the module is not made for Flag 7.x-3.x branch.
I created an issue #2471807: Update to new flags version ("Some flags provided by modules need to be updated to a new format before they can be used with this version of Flag. See the disabled flags for a list of flags that need updating.") to discuss a new version for Flags 3 and am working on a new version with the required changes. It works great and so this can finally be called FIXED. :)
best_answer from #3 is a good alternative if you want a complete feature and not a Flags functionality.
Comment #16
joachim commentedI've just taken a quick look at the code of Flag Solved module, to take note of any particular hooks it uses that we should make sure Flag D8 keeps.
... urgh. It has major problems. It has a hook_init() that saves an action ON EVERY PAGE LOAD. And it uses the theme preprocessor to prevent a flag from showing, rather than acting on hook_flag_access().
Comment #17
anybody@joachim: You are right. I'm currently working on this. I've created a local 7.x-3.x branch of it. If you're interested, let's discuss improvements in the modules issues.
I'm also not sure if actions are the best way to do things there. For my specific case I used rules. Flags 3 also provides some more access settings... all in all the Flags 3 version could be much smarter!