Problem/Motivation

I am building a form which requires access to some of the submission values on a custom confirmation page. It would be great to replace tokens in the confirmation_url, so that I can load the form and pull data out of it.

Proposed resolution

Replace tokens on any settings where it seems appropriate to do so.

Remaining tasks

Patch.

User interface changes

Perhaps the addition of some text describing the behavior?

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sam152 created an issue. See original summary.

Sam152’s picture

Status: Active » Needs review
FileSize
910 bytes

Quick and dirty patch for my purposes. I think the final solution would perhaps work on more settings, be better tested etc.

jrockowitz’s picture

Attached is less 'dirty' patch, that might be okay without any tests. If it works, I can probably just commit it.

Sam152’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

  • jrockowitz committed 5f7bc7f on 8.x-1.x
    Issue #2773827 by Sam152, jrockowitz: Replace yamlform submission tokens...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Done!

jrockowitz’s picture

Status: Fixed » Closed (fixed)
Stephen Ollman’s picture

Should this work on the settings page from the confirmation URL field?

/node/[yamlform-submission:values:my_field_name:value]

Where 'my_field_name' is simply a node ID that called the form via a modal.

Right now I just getting the 'node' page returned, thus the token is being ignored.

Am I right in saying that I can use submission value tokens on the settings page?

Oh and thanks for this module!

Stephen Ollman’s picture

FURTHER TO THIS

I've just noticed that the token works when running it through a test cycle. Configuration URL works a treat, just not when doing it live.

UPDATE

Scrap that whilst the test cycle is redirecting to a node page its totally a random node.

Basically the token is not returning the correct value of the field during a test and totally ignored during a live run.

However I can use the token in the confirmation message, just not the URL.

jrockowitz’s picture

Status: Closed (fixed) » Needs work
jrockowitz’s picture

I think \Drupal\field_ui\Form\EntityDisplayFormBase::copyFormValuesToEntity needs to be called before the tokens are replaced. I just need to determine where this call should be made in \Drupal\yamlform\YamlFormSubmissionForm.

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
804 bytes

Let's see if the attached patch passes.

Status: Needs review » Needs work

The last submitted patch, 12: replace_yamlform-2773827-12.patch, failed testing.

jrockowitz’s picture

Okay, this is going to be much harder than it seems because the setting tokens need to be replaced after the form_state has been populated.

I think all calls to retrieve a YAML Form setting will have to pass thru \Drupal\yamlform\YamlFormSubmissionForm::getYamlFormSetting() which can do lazy token replacement.

Stephen Ollman’s picture

error after applying patch:

Fatal error: Call to a member function extractFormValues() on null in /docroot/core/lib/Drupal/Core/Entity/ContentEntityForm.php on line 223

jrockowitz’s picture

@Stephen Ollman. Thanks reviewing the patch. I am on vacation until 8/1 and fixing this issue is going to require some serious concentration.

Stephen Ollman’s picture

I really appreciate your help and look forward to hopefully seeing a working patch soon. I feel this module will be a big asset to D8.
Enjoy your break!

  • jrockowitz committed 5f7bc7f on 2773827-submission-tokens
    Issue #2773827 by Sam152, jrockowitz: Replace yamlform submission tokens...

  • jrockowitz committed 5f7bc7f on 2773827-submission-tokens
    Issue #2773827 by Sam152, jrockowitz: Replace yamlform submission tokens...

  • jrockowitz committed a960ef1 on 2773827-submission-tokens
    Issue #2773827 by jrockowitz, Sam152, Stephen Ollman: Replace yamlform...
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
14.85 KB

My issue queue is filling up.... got a quiet moment to focus on making the needed tweak.

jrockowitz’s picture

Attached is the form I used to test that submitted values are being used by the confirmation URL.

  • jrockowitz committed 621dd81 on 8.x-1.x
    Issue #2773827 by jrockowitz, Sam152: Replace yamlform submission tokens...
jrockowitz’s picture

Status: Needs review » Fixed
robpowell’s picture

@jrockowitz - the 21 patch didn't work for me locally I got the following error:
patch -p1 --dry-run < replace_yamlform-2773827-21.patch
patching file src/YamlFormSubmissionForm.php
Hunk #1 succeeded at 175 (offset -2 lines).
Hunk #2 succeeded at 210 (offset -2 lines).
Hunk #3 succeeded at 223 (offset -2 lines).
Hunk #4 succeeded at 270 (offset -2 lines).
Hunk #5 succeeded at 280 (offset -2 lines).
Hunk #6 succeeded at 312 (offset -2 lines).
Hunk #7 succeeded at 411 (offset -2 lines).
Hunk #8 succeeded at 421 (offset -2 lines).
Hunk #9 succeeded at 445 (offset -2 lines).
Hunk #10 succeeded at 460 (offset -2 lines).
Hunk #11 succeeded at 479 (offset -2 lines).
Hunk #12 succeeded at 577 (offset -2 lines).
Hunk #13 succeeded at 598 (offset -2 lines).
Hunk #14 succeeded at 621 (offset -2 lines).
Hunk #15 FAILED at 630.
Hunk #16 FAILED at 640.
Hunk #17 succeeded at 889 (offset -14 lines).
Hunk #18 succeeded at 929 (offset -14 lines).
Hunk #19 succeeded at 956 (offset -14 lines).
Hunk #20 succeeded at 963 (offset -14 lines).
Hunk #21 succeeded at 987 (offset -14 lines).
Hunk #22 succeeded at 997 (offset -14 lines).
Hunk #23 succeeded at 1007 (offset -14 lines).
Hunk #24 succeeded at 1110 (offset -14 lines).
Hunk #25 succeeded at 1131 (offset -14 lines).
2 out of 25 hunks FAILED -- saving rejects to file src/YamlFormSubmissionForm.php.rej

also, I tried testing via the simplytest.me link and that error'd and didn't set up the instance.

Stephen Ollman’s picture

Same failure here when applying the patch. Also a number of visual form elements seem to be adversely effected by the patch. ie the submit button.

jrockowitz’s picture

@Stephen Ollman @robpowell I applied the patch to 8.x-1.x so you just need to download the 8.x-1.x-dev release.

Because this module is still in beta and I am trying to get as much done as possible before DrupalCon Dublin, occasionally I will just apply a patch. especially if it passes all the tests and I am comfortable that the issue and solution won't break anything.

Moving forward besides marking the issue as fixed. I will add a comment stating that I applied the patch to 8.x-1.x.

BTW, thanks for taking the time out to review the patches.

Stephen Ollman’s picture

BOOM!

Works like a charm. After enabling 8.x-1.x and applying the patch #21, the confirmation URL token works perfectly.

Great job jrockowitz.

Stephen Ollman’s picture

On a quick side note: is it possible to send email using the username rather than the email address?

jrockowitz’s picture

@Stephen Ollman. I don't understand your request. Do you want just the username displayed as the sender in the email clients?

Feel free to open a new ticket

Stephen Ollman’s picture

If I have a form field that captures the username, can that field be used as the 'To' address component in the email config?

jrockowitz’s picture

This feature is currently not supported by the YAML Form module. I am not sure why but I don't see other form builder's supporting this feature/behavior.

Please open a new ticket.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.