Skip to main content

Managing Flag Development In D8

Submitted by system on
Check if an entity has been flagged: /**@var \Drupal\flag\FlagService $flag_service */
$flag_service = \Drupal::service('flag');
$flag = $flag_service->getFlagById($flag_id);
return $flag->isFlagged($node);

Get all flagging users for an entity and flag: $flagging = $flag_service->getFlaggingUsers($entity, $flag); // $flag is optional
Flag an entity: $flag_service->flag($flag, $entity, $account); // $account is optional
Unflag an entity: $flag_service->unflag($flag, $entity, $account); // $account is optional

Technologies