private function ForwardForm::getToken in Forward 8
Same name and namespace in other branches
- 8.3 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::getToken()
- 8.2 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::getToken()
- 4.x src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::getToken()
- 4.0.x src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::getToken()
Get a token
2 calls to ForwardForm::getToken()
- ForwardForm::buildForm in src/
Form/ ForwardForm.php - Form constructor.
- ForwardForm::submitForm in src/
Form/ ForwardForm.php - Form submission handler.
File
- src/
Form/ ForwardForm.php, line 206
Class
- ForwardForm
- Forward a page to a friend
Namespace
Drupal\forward\FormCode
private function getToken(FormStateInterface $form_state = NULL) {
$token = array();
if ($form_state && $form_state
->getValue('name')) {
// Harden the name field against abuse. @see https://www.drupal.org/node/2793891
$token = [
'forward' => [
'sender_name' => $this
->cleanString($form_state
->getValue('name')),
],
];
}
elseif ($this
->currentUser()
->isAuthenticated()) {
$token = [
'forward' => [
'sender_name' => $this
->currentUser()
->getDisplayName(),
],
];
}
if ($form_state && $form_state
->getValue('email')) {
$token['forward']['sender_email'] = $form_state
->getValue('email');
}
elseif ($this
->currentUser()
->isAuthenticated()) {
$token['forward']['sender_email'] = $this
->currentUser()
->getEmail();
}
if ($form_state) {
$token['forward']['entity'] = $form_state
->get('#entity');
}
// Allow other modules to add more tokens
if ($extra_tokens = $this->moduleHandler
->invokeAll('forward_token', array(
$form_state,
))) {
$token += $extra_tokens;
}
return $token;
}