public function ActionLinkNoJsController::flag in Flag Lists 8
Same name and namespace in other branches
- 4.0.x src/Controller/ActionLinkNoJsController.php \Drupal\flag_lists\Controller\ActionLinkNoJsController::flag()
Performs a flagging when called via a route.
Parameters
\Drupal\flag\FlagInterface $flag: The flag entity.
int $entity_id: The flaggable entity ID.
string $flag_list: The flag list from the link.
Return value
\Symfony\Component\HttpFoundation\RedirectResponse|null The response object, only if successful.
See also
\Drupal\flag\Plugin\Reload
1 string reference to 'ActionLinkNoJsController::flag'
File
- src/
Controller/ ActionLinkNoJsController.php, line 91
Class
- ActionLinkNoJsController
- Returns nojs responses to flag and unflag action links.
Namespace
Drupal\flag_lists\ControllerCode
public function flag(FlagInterface $flag, $entity_id, $flag_list) {
/* @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this->flagService
->getFlaggableById($flag, $entity_id);
try {
$this->flagService
->flag($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.
}
// Create the flag list item.
$actionLinkHelper = new ActionLinkHelper($this->flagListsService);
$actionLinkHelper
->flagHelper($flag, $entity_id, $flag_list);
return $this
->generateResponse($entity, $flag
->getMessage('flag'));
}