How to assign a value of Webform Element (IP_ADDRESS
) to a Custom Token ?
The Step that I did:
use Drupal\webform\WebformSubmissionInterface;
function MODULE_token_info() {
// token info
}
function MODULE_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata, WebformSubmissionInterface $webform_submission = NULL) {
// @var to return IP address of the submission.
$ip = $webform_submission->getRemoteAddr();
$replacements = [];
if ($type == 'custom') {
foreach ($tokens as $name => $original) {
switch ($name) {
case 'order-cart':
$replacements[$original] = t('First Value');
break;
case 'city-token':
$replacements[$original] = getCity($ip);
break;
}
}
}
return $replacements;
}
However, IP_ADDRESS
always return NULL.
I'm sure the $ip var is not the right way to retrieve Element value. and that's the issue.
So, How to return the value of Webform Submission IP Address? `
I'll appreciate the help, Thanks