Skip to content

Commit

Permalink
Merge pull request #335 from nishant-bhorodia/CATL-1564-case-tags-val…
Browse files Browse the repository at this point in the history
…ue-hidden-field

CATL-1564: Handle hidden (select) fields in submissions and emails
  • Loading branch information
colemanw authored Aug 24, 2020
2 parents 63bd2ca + 8e18335 commit e00b307
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions webform_civicrm.module
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,39 @@ function webform_civicrm_webform_submission_load(&$submissions) {

/**
* Implements hook_webform_submission_render_alter().
* Add display name to title while viewing a submission.
*/
function webform_civicrm_webform_submission_render_alter(&$sub) {
if (!empty($sub['#submission']->civicrm['contact'][1]['display_name']) && empty($sub['#email']) && $sub['#format'] == 'html') {
drupal_set_title(t('Submission #!num by @name', ['!num' => $sub['#submission']->sid, '@name' => $sub['#submission']->civicrm['contact'][1]['display_name']]));
function webform_civicrm_webform_submission_render_alter(&$renderable) {
// Add display name to title while viewing a submission.
if (!empty($renderable['#submission']->civicrm['contact'][1]['display_name']) && empty($renderable['#email']) && $renderable['#format'] == 'html') {
drupal_set_title(t('Submission #!num by @name', ['!num' => $renderable['#submission']->sid, '@name' => $renderable['#submission']->civicrm['contact'][1]['display_name']]));
}

// Show labels for hidden (select) fields when submissions are rendered.
foreach ($renderable['#node']->webform['components'] as $component) {
if ($component['type'] == 'hidden') {
$options = wf_crm_field_options($component, 'submission', $renderable['#node']->webform_civicrm['data']);
if (empty($options)) {
continue;
}
$parentkeys = webform_component_parent_keys($renderable['#node'], $component);
$value = &$renderable[array_shift($parentkeys)];
foreach ($parentkeys as $parentkey) {
$value = &$value[$parentkey];
}

// Handle multiple values.
if (!empty($component['extra']['multiple'])) {
$selected_options = explode(',', $value['#markup']);
$items = [];
foreach ($selected_options as $selected_option) {
$items[] = $options[$selected_option];
}
$value['#markup'] = implode(', ', $items);
}
else {
$value['#markup'] = $options[$value['#markup']];
}
}
}
}

Expand Down

0 comments on commit e00b307

Please sign in to comment.