You are here

function _webform_render_markup_after_build in Webform 7.4

Helper function to replace tokens in markup component.

Required to have access to current form values from $form_state.

1 string reference to '_webform_render_markup_after_build'
_webform_render_markup in components/markup.inc
Implements _webform_render_component().

File

components/markup.inc, line 110
Webform module markup component.

Code

function _webform_render_markup_after_build($form_element, &$form_state) {
  global $user;
  $node = node_load($form_element['#webform_nid']);
  $submission = NULL;

  // Convert existing submission data to an in-progress submission.
  $form_state_for_submission = $form_state;
  $form_state_for_submission['values']['submitted'] = $form_state['#conditional_values'];
  module_load_include('inc', 'webform', 'includes/webform.submissions');
  $submission = webform_submission_create($node, $user, $form_state_for_submission, TRUE, $form_element['#webform_submission']);

  // Replace tokens using the current or generated submission.
  $value = webform_replace_tokens($form_element['#markup'], $node, $submission, NULL, $form_element['#webform_format']);

  // If the markup value has been set by a conditional, display that value.
  $component = $form_element['#webform_component'];
  if ($node) {
    $sorter = webform_get_conditional_sorter($node);

    // If the form was retrieved from the form cache, the conditionals may not
    // have been executed yet.
    if (!$sorter
      ->isExecuted()) {
      $sorter
        ->executeConditionals(isset($submission) ? $submission->data : array());
    }
    $conditional_value = $sorter
      ->componentMarkup($component['cid'], $component['page_num']);
    if (isset($conditional_value)) {

      // Provide original value, should conditional logic no longer set the
      // value.
      $form_element['#wrapper_attributes']['data-webform-markup'] = $value;
      if (is_string($conditional_value)) {
        $value = check_markup($conditional_value, $component['extra']['format']);
      }
    }
  }
  $form_element['#markup'] = $value;
  return $form_element;
}