Commit f757e5e4 authored by Harold Aling's avatar Harold Aling Committed by Harold Aling
Browse files

Issue #2644446 by MrHaroldA: Submission display does not render correctly

parent ccc40aa8
Loading
Loading
Loading
Loading
+20 −14
Changes for dvg_appointments.module: 20 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ function dvg_appointments_menu() {
 * Implements hook_module_implements_alter().
 */
function dvg_appointments_module_implements_alter(&$implementations, $hook) {
  _dvg_global_module_implements_first('dvg_appointments', array('webform_submission_presave'), $implementations, $hook);
  _dvg_global_module_implements_last('dvg_appointments', array('webform_submission_load', 'form_alter'), $implementations, $hook);
  _dvg_global_module_implements_first('dvg_appointments', array('webform_submission_presave', 'webform_submission_load'), $implementations, $hook);
  _dvg_global_module_implements_last('dvg_appointments', array('form_alter'), $implementations, $hook);
}

/**
@@ -356,7 +356,14 @@ function _webform_display_wa_product($component, $values, $format = 'html') {

  $client = dvg_appointments_get_client_api();
  $products = $client->get_available_products();
  $display = array();
  $display = array(
    '#title' => $component['name'],
    '#weight' => $component['weight'],
    '#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'),
    '#post_render' => array('webform_element_wrapper'),
    '#component' => $component,
  );

  foreach ($values as $value) {
    $product = $products[$value['product']];
    if ($format == 'html') {
@@ -372,11 +379,6 @@ function _webform_display_wa_product($component, $values, $format = 'html') {
    }

    $display[] = array(
      '#title' => $component['name'],
      '#weight' => $component['weight'],
      '#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'),
      '#post_render' => array('webform_element_wrapper'),
      '#component' => $component,
      '#format' => $format,
      '#markup' => $display_value,
      '#parents' => array(FALSE),
@@ -384,10 +386,6 @@ function _webform_display_wa_product($component, $values, $format = 'html') {
    );
  }

  if (count($display) == 1) {
    $display = $display[0];
  }

  return $display;
}

@@ -403,7 +401,7 @@ function _webform_display_wa_date_time($component, $value, $format = 'html') {
    '#post_render' => array('webform_element_wrapper'),
    '#component' => $component,
    '#format' => $format,
    '#value' => isset($value[0]) ? dvg_appointments_format_date($value[0], 'Y-m-d G:i:s') : '',
    '#value' => isset($value[0]) ? dvg_appointments_format_date($value[0], 'day_date_time') : '',
  );
}

@@ -523,6 +521,11 @@ function dvg_appointments_webform_submission_presave($node, &$submission) {
  $wa_email = dvg_appointments_get_cid($node, 'wa_email');

  if ($wa_product) {

    // Move the appointment data out of the submission data to prevent errors on the submission display.
    $submission->dvg_appointments = $submission->data[$wa_product]['appointments'];
    unset($submission->data[$wa_product]['appointments']);

    foreach ($submission->data[$wa_product] as $dcid => $data) {
      $submission->data[$wa_product][$dcid] = serialize($data);
    }
@@ -539,7 +542,7 @@ function dvg_appointments_webform_submission_presave($node, &$submission) {
 */
function dvg_appointments_webform_submission_insert($node, $submission) {
  if ($wa_product = dvg_appointments_get_cid($node, 'wa_product')) {
    $data = unserialize($submission->data[$wa_product]['appointments']);
    $data = $submission->dvg_appointments;
    /** @var DvGAppointment $appointment */
    $appointment = $data['appointment'];
    $appointment->setNodeId($submission->nid);
@@ -848,6 +851,9 @@ function dvg_appointments_format_date($time, $type, $format = '') {
    case 'day_date':
      $date_formatted = format_date($time, 'custom', 'l, j F Y', $api_client->get_timezone());
      break;
    case 'day_date_time':
      $date_formatted = format_date($time, 'custom', 'l, j F Y H:i', $api_client->get_timezone());
      break;
    case 'year':
      $date_formatted = format_date($time, 'custom', 'Y', $api_client->get_timezone());
      break;