You are here

public function FlagServiceInterface::unflag in Flag 8.4

Unflags the given entity for the given flag.

$flag_service = \Drupal::service('flag');
$flag = $flag_service
  ->getFlagById('bookmark');
$node = Node::load($node_id);
$flag_service
  ->unflag($flag, $node);

Parameters

\Drupal\flag\FlagInterface $flag: The flag being unflagged.

\Drupal\Core\Entity\EntityInterface $entity: The entity to unflag.

\Drupal\Core\Session\AccountInterface $account: (optional) The account of the user that created the flagging. Defaults to the current user.

string $session_id: (optional) If $account is anonymous then the $session_id MUST be used to identify a user uniquely. If $account and $session_id are NULL and the current user is anonymous then the current session_id will be used.

Throws

\LogicException An exception is thrown if the given flag, entity, and account are not compatible in some way:

  • The flag applies to a different entity type from the given entity.
  • The flag does not apply to the entity's bundle.
  • The entity is not currently flagged with this flag by the user.
  • The user is anonymous but not uniquely identified by session_id.
1 method overrides FlagServiceInterface::unflag()
FlagService::unflag in src/FlagService.php
Unflags the given entity for the given flag.

File

src/FlagServiceInterface.php, line 254

Class

FlagServiceInterface
Flag service interface.

Namespace

Drupal\flag

Code

public function unflag(FlagInterface $flag, EntityInterface $entity, AccountInterface $account = NULL, $session_id = NULL);