У меня есть специальный модуль, который берет адрес электронной почты из формы и вставляет ссылку в обработчик электронной почты (через токен), который при нажатии переходит на другую веб-форму и при отправке отправляет ответ на исходный адрес электронной почты. ,
Я пытаюсь передать отправленные значения из первой формы по этой ссылке, но она не работает:
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_alter() for webform.
*
* Add the custom validation handler to the 'webform-1'.
*/
function webformcustom_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'webform_submission_get_offers_add_form') {
$form['#validate'][] = 'webformcustom_validator';
}
}
/**
* The custom validation handler.
*
* Get an email of a user, encrypt it and insert it
* into the body of the notification email.
* Generate a random token and store it with a user's email as a 'key'/'value'
* using State API.
* A token that is added to the link on the webform_2 as the argument,
* like this: http://drupal8.dev/form/webform-2?token=fb41566252aec769.
* This token then will be using in the hook_preprocess_HOOK() for extraction
* of a user's email.
*/
function webformcustom_validator(&$form, FormStateInterface $form_state) {
$email = $form_state->getValue('email_address');
$webform = \Drupal::entityTypeManager()
->getStorage('webform')
->load('get_offers');
$email_handler = $webform->getHandler('email');
$configuration = $email_handler->getConfiguration();
// Generate a random token.
$token = bin2hex(openssl_random_pseudo_bytes(8));
\Drupal::state()->set('webformcustom_' . $token, $email);
$url = \Drupal::urlGenerator()->generateFromRoute('<front>', [], ['absolute' => TRUE]);
$url .= 'provide-a-quote/?select_a_car=[webform-submission:values:select_a_car]&token=' . $token;
// Insert the link to the 'webform-2' with the token into the email body.
$configuration['settings']['body'] = '<a href=' . $url . '>Submit offer</a>';
$email_handler->setConfiguration($configuration);
}
/**
* Implements hook_preprocess_HOOK() for webform templates.
*
* Read the token from the url and extract related a user's email.
* Then set a user's email in to the email handler configuration.
* This enables to notify a user when the 'webform_2' will be submit.
*/
function webformcustom_preprocess_webform(&$variables) {
if ($variables['element']['#webform_id'] == 'provide_a_quote') {
$token = \Drupal::request()->query->get('token');
$email = \Drupal::state()->get('webformcustom_' . $token);
$webform = \Drupal::entityTypeManager()
->getStorage('webform')
->load('provide_a_quote');
$email_handler = $webform->getHandler('email');
$configuration = $email_handler->getConfiguration();
$configuration['settings']['to_mail'] = $email;
$email_handler->setConfiguration($configuration);
$webform->save();
}
}
Что мне дает ссылка в письме неработающая ссылка:
Audi? token = 01f89ea29aa5251f> Ссылка на webfrom-2