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.
How to implements hook_flag_flag() / hook_flag_unflag in flag 8.x-4.X ?
I read the documentation but can not found it.
Thanks in advance.
Comment | File | Size | Author |
---|---|---|---|
#9 | 05-flag-email-recent-log-messages-after-add-condition.png | 33.46 KB | anjjriit |
#9 | 04-flag-email-recent-log-messages-before-add-condition.png | 32.15 KB | anjjriit |
#8 | 03-flag-email-detail-log-messages.png | 26.41 KB | anjjriit |
#8 | 02-flag-email-recent-log-messages.png | 15.05 KB | anjjriit |
#8 | 01-flag-email-extend.png | 22.77 KB | anjjriit |
Comments
Comment #2
martin107 CreditAttribution: martin107 commentedHi anjjriit
Can you add an outline of what task you want to perform?
The answer to your question will involve calling FlagServiceInterface::flag()/unflag()
In some way, but that is only a small piece of the puzzle
I will try and help out where possible.
An example for something that calls FlugService Interface::flag() see ActionLinkController::flag()
Comment #3
anjjriit CreditAttribution: anjjriit commented@martin107 Thanks a lot for quick reply
a simple action what i want to perform when a node was flagged is send an email to specific person, not as node author or current user
Comment #4
socketwench CreditAttribution: socketwench at FFW commentedBoth hook_flag_flag() and hook_flag_unflag() were replaced with an event: #2409859: [Policy, No Patch] Where did the Flag 7.x hooks go in 8.x?
Comment #5
martin107 CreditAttribution: martin107 commentedPlease ignore #2, Socketwench is correct ... as usual
Can I ask a few questions!
(A) Are we speaking about one node and there will be many types of flags -- each flag causing an email to be sent
OR
(B) Are we talking about one special flag with the property that an email will be sent
I think my advice changes depending on A or B
The solution might involve creating a new service similar to FlagCountManager
What is key is the EventSubscriberInterface part
and the getSubscribedEvents method which binds methods which will trigger the email generation.
Anyway I hope this is food for thought.
Comment #6
anjjriit CreditAttribution: anjjriit commentedIn this issue we are speaking about special flag, or option (B).
I have flag named needs_review and when its flagged I want to send an email
but i do not want to send email when bookmark is flagged.
Comment #7
martin107 CreditAttribution: martin107 commentedFor some time I have wanted a example sub-module that makes use of the event system.
it is better to discuss performance issues publically to ensure the pattern we think is good is actually good.
So I have included a new submodule called flag_email
It is an unfinished example
if you install it for example with
drush en flag_email
Then on every article you will see a new "trigger email" flag.
\Drupal\contact\MailerHandler has a good example of how to generate emails
No email is currently sent - at the moment is just adds a log message every time the link is clicked.
The new Mail handler class needs setup methods to define the email address to send a message etc.
If you think this will answer your problem, then I will continue.
@anjjriit can you look at MailManager::generateEmail()
Can you supply/describe a test condition that identifies your special flag.
I would like to fit the example code to match a real world example.
Comment #8
anjjriit CreditAttribution: anjjriit commented@martin107 a tons of Thanks !
This sample sub module is work fine for me.
and my log is in image 02
Comment #9
anjjriit CreditAttribution: anjjriit commentedForgot about IF Condition this my continued test.
i put logger command in two diffrerent place
Comment #10
ptmkenny CreditAttribution: ptmkenny commentedClosing this issue because the original question was answered in #4 and four years have passed with no updates.