5 * Webform module markup component.
9 * Implements _webform_defaults_component().
11 function _webform_defaults_markup() {
21 'display_on' => 'form',
27 * Implements _webform_theme_component().
29 function _webform_theme_markup() {
31 'webform_display_markup' => array(
32 'render element' => 'element',
33 'file' => 'components/markup.inc',
39 * Implements _webform_edit_component().
41 function _webform_edit_markup($component) {
43 $form['value'] = array(
44 '#type' => 'text_format',
45 '#title' => t('Value'),
46 '#default_value' => $component['value'],
47 '#description' => t('Markup allows you to enter custom HTML into your form.') . ' ' . theme('webform_token_help', array('groups' => array('node', 'submission'))),
49 '#format' => $component['extra']['format'],
50 '#element_validate' => array('_webform_edit_markup_validate'),
53 $form['display']['display_on'] = array(
55 '#title' => t('Display on'),
56 '#default_value' => $component['extra']['display_on'],
58 'form' => t('form only'),
59 'display' => t('viewed submission only'),
60 'both' => t('both form and viewed submission'),
63 '#parents' => array('extra', 'display_on'),
70 * Element validate handler; Set the text format value.
72 function _webform_edit_markup_validate($form, &$form_state) {
73 if (is_array($form_state['values']['value'])) {
74 $form_state['values']['extra']['format'] = $form_state['values']['value']['format'];
75 $form_state['values']['value'] = $form_state['values']['value']['value'];
80 * Implements _webform_render_component().
82 function _webform_render_markup($component, $value = NULL, $filter = TRUE, $submission = NULL) {
86 '#title' => $filter ? NULL : $component['name'],
87 '#weight' => $component['weight'],
88 '#markup' => $component['value'],
89 '#format' => $component['extra']['format'],
90 '#theme_wrappers' => array('webform_element'),
91 '#translatable' => array('title', 'markup'),
92 '#access' => $component['extra']['display_on'] != 'display',
93 '#webform_nid' => isset($component['nid']) ? $component['nid'] : NULL,
94 '#webform_submission' => $submission,
95 '#webform_format' => $component['extra']['format'],
99 $element['#after_build'] = array('_webform_render_markup_after_build');
106 * Helper function to replace tokens in markup component.
108 * Required to have access to current form values from $form_state.
110 function _webform_render_markup_after_build($form_element, &$form_state) {
112 $node = node_load($form_element['#webform_nid']);
115 // Convert existing submission data to an in-progress submission.
116 $form_state_for_submission = $form_state;
117 $form_state_for_submission['values']['submitted'] = $form_state['#conditional_values'];
118 module_load_include('inc', 'webform', 'includes/webform.submissions');
119 $submission = webform_submission_create($node, $user, $form_state_for_submission, TRUE, $form_element['#webform_submission']);
121 // Replace tokens using the current or generated submission.
122 $value = webform_replace_tokens($form_element['#markup'], $node, $submission, NULL, $form_element['#webform_format']);
124 // If the markup value has been set by a conditional, display that value.
125 $component = $form_element['#webform_component'];
127 $sorter = webform_get_conditional_sorter($node);
128 // If the form was retrieved from the form cache, the conditionals may not
129 // have been executed yet.
130 if (!$sorter->isExecuted()) {
131 $sorter->executeConditionals(isset($submission) ? $submission->data : array());
133 $conditional_value = $sorter->componentMarkup($component['cid'], $component['page_num']);
134 if (isset($conditional_value)) {
135 // Provide original value, should conditional logic no longer set the value.
136 $form_element['#wrapper_attributes']['data-webform-markup'] = $value;
137 if (is_string($conditional_value)) {
138 $value = check_markup($conditional_value, $component['extra']['format']);
143 $form_element['#markup'] = $value;
144 return $form_element;
149 * Implements _webform_display_component().
151 function _webform_display_markup($component, $value, $format = 'html', $submission = array()) {
152 $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
153 $value = webform_replace_tokens($component['value'], $node, $submission, NULL, $component['extra']['format']);
155 // If the markup value has been set by a conditional, display that value.
156 if ($node && is_string($conditional_value = webform_get_conditional_sorter($node)->componentMarkup($component['cid'], $component['page_num']))) {
157 $value = check_markup($conditional_value, $component['extra']['format']);
161 '#weight' => $component['weight'],
162 '#theme' => 'webform_display_markup',
163 '#format' => $format,
165 '#translatable' => array('title'),
166 '#access' => $component['extra']['display_on'] != 'form',
171 * Format the output of data for this component.
173 function theme_webform_display_markup($variables) {
174 $element = $variables['element'];
175 return $element['#access'] ? $element['#value'] : '';