public function ActionLinkController::unflag in Flag 8.4
Performs a unflagging when called via a route.
Parameters
\Drupal\flag\FlagInterface $flag: The flag entity.
int $entity_id: The flaggable entity ID.
Return value
\Drupal\Core\Ajax\AjaxResponse|null The response object, only if successful.
See also
\Drupal\flag\Plugin\Reload
1 string reference to 'ActionLinkController::unflag'
File
- src/
Controller/ ActionLinkController.php, line 101
Class
- ActionLinkController
- Controller responses to flag and unflag action links.
Namespace
Drupal\flag\ControllerCode
public function unflag(FlagInterface $flag, $entity_id) {
/* @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this->flagService
->getFlaggableById($flag, $entity_id);
try {
$this->flagService
->unflag($flag, $entity);
} catch (\LogicException $e) {
// Fail silently so we return to the entity, which will show an updated
// link for the existing state of the flag.
}
return $this
->generateResponse($flag, $entity, $flag
->getMessage('unflag'));
}