Hi, sorry if this is a noob question... but having gone through the documentation and other issues i cant seem to find an working example for d8 and flags.
I am trying to unflag all current users nodes when they submit a webform. I have my form alter working on the webform submit, but subsequently i cant seem to unflag the current users flags. Anon user may also flag nodes, so this example below doesnt do the trick for me in that context: Having looked at the documentation, most of it is for d7.... unless im missing something?
$flag_service = \Drupal::service('flag');
$flag = $flag_service->getFlagById('flag_machine_name');
// $entity can be $node or user, $account is the acting user.
$flag_service->unflag($flag, $entity, $account);
Any help would be greatly appreciated.
Comments
Comment #2
socketwench commentedThere's a few more methods on FlagService that might help:
The documentation is on the interface, FlagServiceInterface, rather than the FlagService class itself. Does that help?
Comment #3
ptmkenny commentedClosing because #2 gives some hints and there hasn't been a follow-up for 3 years.