public function FieldEntryFormController::flag in Flag 8.4
Performs a flagging when called via a route.
Parameters
\Drupal\flag\FlagInterface $flag: The flag entity.
int $entity_id: The flaggable ID.
Return value
array The processed form to create the flagging.
See also
\Drupal\flag\Plugin\ActionLink\AJAXactionLink
1 string reference to 'FieldEntryFormController::flag'
File
- src/
Controller/ FieldEntryFormController.php, line 68
Class
- FieldEntryFormController
- Provides a controller for the Field Entry link type.
Namespace
Drupal\flag\ControllerCode
public function flag(FlagInterface $flag, $entity_id) {
$flag_id = $flag
->id();
// Set account and session ID to NULL to get the current user.
$account = $session_id = NULL;
$this->flagService
->populateFlaggerDefaults($account, $session_id);
$flagging = $this
->entityTypeManager()
->getStorage('flagging')
->create([
'flag_id' => $flag
->id(),
'entity_type' => $flag
->getFlaggableEntityTypeId(),
'entity_id' => $entity_id,
'uid' => $account
->id(),
'session_id' => $session_id,
]);
return $this
->getForm($flagging, 'add');
}