In some cases it would be good to be able to use [submission:values:…] tokens in default values of other components. Naturally this would be limited to work with the values from earlier pages in the form.

Proposed solution

  • Create a temporary submission object webform_client_form() and pass it to all _webform_render_*() implementations.
  • Pass the $submission parameter to all invocations webform_replace_tokens() and webform_filter_descriptions() (at least in _webform_render_*() implementations.

Current state

  • A patch implementing this is provided
  • The idea and its implementation need review and discussion.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torotil created an issue. See original summary.

torotil’s picture

Status: Active » Needs review
FileSize
16.89 KB
Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 2 year old patch in #2 does not apply to the latest 7.x-4.x-dev so needs a reroll.

Checking patch components/date.inc...
Checking patch components/email.inc...
Hunk #1 succeeded at 148 (offset -1 lines).
Checking patch components/fieldset.inc...
Checking patch components/file.inc...
Hunk #1 succeeded at 354 (offset -8 lines).
Checking patch components/grid.inc...
Checking patch components/hidden.inc...
Checking patch components/number.inc...
Hunk #1 succeeded at 289 (offset 10 lines).
Checking patch components/select.inc...
Hunk #1 succeeded at 332 (offset 1 line).
Hunk #2 succeeded at 343 (offset 1 line).
Hunk #3 succeeded at 930 (offset -1 lines).
Checking patch components/textarea.inc...
Hunk #1 succeeded at 113 (offset -1 lines).
Checking patch components/textfield.inc...
error: while searching for:
    '#type' => 'textfield',
    '#title' => $filter ? webform_filter_xss($component['name']) : $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
    '#default_value' => $filter ? webform_replace_tokens($component['value'], $node) : $component['value'],
    '#required' => $component['required'],
    '#weight' => $component['weight'],
    '#field_prefix' => empty($component['extra']['field_prefix']) ? NULL : ($filter ? webform_filter_xss($component['extra']['field_prefix']) : $component['extra']['field_prefix']),
    '#field_suffix' => empty($component['extra']['field_suffix']) ? NULL : ($filter ? webform_filter_xss($component['extra']['field_suffix']) : $component['extra']['field_suffix']),
    '#description' => $filter ? webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
    '#attributes' => $component['extra']['attributes'],
    '#theme_wrappers' => array('webform_element'),
    '#translatable' => array('title', 'description', 'field_prefix', 'field_suffix'),

error: patch failed: components/textfield.inc:139
error: components/textfield.inc: patch does not apply
Checking patch components/time.inc...
Checking patch webform.module...
error: while searching for:
    // webform components and b) the error will be apparent upon submission.
    webform_input_vars_check($form, $form_state, 'submitted');

    // Recursively add components to the form. The unfiltered version of the
    // form (typically used in Form Builder), includes all components.
    foreach ($component_tree['children'] as $cid => $component) {

error: patch failed: webform.module:2584
error: webform.module: patch does not apply
lucassc’s picture

Rerolled for 7.x-4.x.

I was not able to add an interdiff:

interdiff 2817093-2-tokens-in-default-values.patch 2817093-04.patch > interdiff_02-04.txt
1 out of 1 hunk FAILED -- saving rejects to file /tmp/interdiff-1.8tgmm2.rej
interdiff: Error applying patch1 to reconstructed file

So I just added a diff, hope it does the job.

Please, review.

lucassc’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll