In working with tokens, I found a few issues:
1) webform.tokens.inc, webform_token_info() contains:
$webform_submission['view-url'] = [
'name' => t('Update (token) URL'),
'description' => t('The URL that can used to view the webform submission. The webform must be configured to allow users to view a submission using a secure token.'),
];
The name is obvious wrong. Should probably be "View (token) URL" or similar.
2) WebformSubmission::getTokenURL() has an inconsistency. For view, it returns a relative URL, but for update it returns an absolute URL (because it calls getSourceUrl() and that's what it returns. For consistency, the view case should probably be:
$uri = $request_handler->getUrl($this, $this->getSourceEntity(), 'webform.user.submission')->setOption('absolute', TRUE);
... where the ->setOption('absolute', TRUE) is my suggested change.
3) I went through some effort to add the standard URL token modifiers to the view-url, update-url, and source-url tokens so that I could specify [webform-submission:view-url:absolute]. However if the change to 2 is made, then this probably isn't necessary or needed by anyone. The use case for absolute url's is to include them in webform email handler email messages. I will post a patch for the work I did just to preserve it for anyone else that might want it. I'm NOT suggest this be tested and committed. I am personally not using these tokens as I want ones without the URL query token ?token=xxx. (Confusing using token in two different means here.)
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3094014-9.patch | 6.58 KB | jrockowitz |
| #6 | 3094014-4.patch | 3.76 KB | jrockowitz |
| #4 | 3094014-4.patch | 3.73 KB | jrockowitz |
| #2 | url_token_modifiers-untested-3094014.2.patch | 2.03 KB | danchadwick |
Comments
Comment #2
danchadwick commentedHere's a patch for issue 3 for anyone in the future to use or build off of. Again, not suggesting issue 3 be worked on by maintainers.
I could make patches for issues 1 and 2, but they are trivial so I won't unless asked.
Comment #3
jrockowitz commentedWow! That is an awesome improvement. I will review the patch in-depth when I have some time available.
Comment #4
jrockowitz commentedI agree with 2) and the view-url token is a new feature that has not been shared in a stable release.
The attached patch changes $uri to $url and moves the more complex URL tokens processing after the entity token.
Comment #5
jrockowitz commentedComment #6
jrockowitz commentedJust fixing the typo in the view-url token.
Comment #7
danchadwick commentedNot seeing that you've addressed issue 2 (inconsistent results of view versus update in getTokenUrl). Maybe this was intentional?
Comment #8
jrockowitz commented2) is addressed by
$options = $url->setAbsolute()->getOptions();.I still need to add some basic test coverage.
Comment #9
jrockowitz commentedThe attached patch adds some very basic test coverage.
Comment #10
danchadwick commentedOh, gotcha. Didn't see that there. +1
I have read over the patch and it looks good to me. I have not conducted any manual testing, so I'm relying upon the code review and limited automated test coverage in doing so.
Comment #12
jrockowitz commentedI committed the patch.
What I like about tokens is generally they either work as expected or they don't