Projet

Général

Profil

Révision c22e192e

Ajouté par Assos Assos il y a plus de 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform/webform.module
1233 1233
}
1234 1234

  
1235 1235
/**
1236
 * Implements hook_delete().
1236
 * Implements hook_node_delete().
1237 1237
 */
1238 1238
function webform_node_delete($node) {
1239 1239
  if (!in_array($node->type, webform_variable_get('webform_node_types'))) {
......
1434 1434
    return;
1435 1435
  }
1436 1436

  
1437
  // If the webform is not set to display in this view mode, return early.
1438
  $extra_fields = field_extra_fields_get_display('node', $node->type, $view_mode);
1439
  if (empty($extra_fields['webform']['visible'])) {
1440
    return;
1441
  }
1442

  
1437 1443
  $info = array();
1438 1444
  $submission = array();
1439 1445
  $submission_count = 0;
......
1521 1527
    }
1522 1528
  }
1523 1529

  
1524
  // Render the form and generate the output.
1525
  $form = !empty($node->webform['components']) ? drupal_get_form('webform_client_form_' . $node->nid, $node, $submission, $is_draft) : '';
1530
  // Avoid building the same form twice on the same page request (which can
1531
  // happen if the webform is displayed in a panel or block) because this
1532
  // causes multistep forms to build incorrectly the second time.
1533
  $cached_forms = &drupal_static(__FUNCTION__, array());
1534
  if (isset($cached_forms[$node->nid])) {
1535
    $form = $cached_forms[$node->nid];
1536
  }
1537
  // If this is the first time, generate the form array.
1538
  else {
1539
    $form = drupal_get_form('webform_client_form_' . $node->nid, $node, $submission, $is_draft);
1540
    $cached_forms[$node->nid] = $form;
1541
  }
1526 1542

  
1527 1543
  // Remove the surrounding <form> tag if this is a preview.
1528 1544
  if (!empty($node->in_preview)) {
......
2626 2642
 */
2627 2643
function _webform_confirmation($node) {
2628 2644
  drupal_set_title($node->title);
2629
  webform_set_breadcrumb($node);
2645
  webform_set_breadcrumb($node, TRUE);
2630 2646
  $sid = isset($_GET['sid']) ? $_GET['sid'] : NULL;
2631 2647
  return theme(array('webform_confirmation_' . $node->nid, 'webform_confirmation'), array('node' => $node, 'sid' => $sid));
2632 2648
}
......
2946 2962
    $replacements['email'][$format] = array();
2947 2963

  
2948 2964
    // Populate token values for each component.
2949
    foreach ($submission->data as $cid => $value) {
2950
      $component = $node->webform['components'][$cid];
2951

  
2965
    foreach ($node->webform['components'] as $cid => $component) {
2952 2966
      // Find by form key.
2953 2967
      $parents = webform_component_parent_keys($node, $component);
2954 2968
      $form_key = implode('][', $parents);
2955
      $display_element = webform_component_invoke($component['type'], 'display', $component, $value['value'], $format);
2969
      if (isset($submission->data[$cid])) {
2970
        $value = $submission->data[$cid];
2956 2971

  
2957
      // Ensure the component is added as a property.
2958
      $display_element['#webform_component'] = $component;
2972
        $display_element = webform_component_invoke($component['type'], 'display', $component, $value['value'], $format);
2973

  
2974
        // Ensure the component is added as a property.
2975
        $display_element['#webform_component'] = $component;
2959 2976

  
2960
      if (empty($display_element['#parents'])) {
2961
        $display_element['#parents'] = array_merge(array('submitted'), $parents);
2977
        if (empty($display_element['#parents'])) {
2978
          $display_element['#parents'] = array_merge(array('submitted'), $parents);
2979
        }
2980
        if (empty($display_element['#id'])) {
2981
          $display_element['#id'] = drupal_html_id('edit-' . implode('-', $display_element['#parents']));
2982
        }
2983
        $replacements['email'][$format]['%email[' . $form_key . ']'] = render($display_element);
2984
        $display_element['#theme_wrappers'] = array(); // Remove label and wrappers.
2985
        $replacements['email'][$format]['%value[' . $form_key . ']'] = render($display_element);
2962 2986
      }
2963
      if (empty($display_element['#id'])) {
2964
        $display_element['#id'] = drupal_html_id('edit-' . implode('-', $display_element['#parents']));
2987
      else {
2988
        // Provide an empty value for components without submitted data.
2989
        $replacements['email'][$format]['%email[' . $form_key . ']'] = '';
2990
        $replacements['email'][$format]['%value[' . $form_key . ']'] = '';
2965 2991
      }
2966
      $replacements['email'][$format]['%email[' . $form_key . ']'] = render($display_element);
2967
      $display_element['#theme_wrappers'] = array(); // Remove label and wrappers.
2968
      $replacements['email'][$format]['%value[' . $form_key . ']'] = render($display_element);
2969
    }
2970

  
2971
    // Provide blanks for components in the webform but not in the submission.
2972
    $missing_components = array_diff_key($node->webform['components'], $submission->data);
2973
    foreach ($missing_components as $component) {
2974
      $parents = webform_component_parent_keys($node, $component);
2975
      $form_key = implode('][', $parents);
2976
      $replacements['email'][$format]['%email[' . $form_key . ']'] = '';
2977
      $replacements['email'][$format]['%value[' . $form_key . ']'] = '';
2978 2992
    }
2993
    // Reverse the order of tokens so that nested tokens (ie. inside fieldsets)
2994
    // come before their parents.
2995
    $replacements['email'][$format] = array_reverse($replacements['email'][$format]);
2979 2996

  
2980 2997
    // Submission edit URL.
2981 2998
    $replacements['unsafe']['%submission_url'] = url('node/' . $node->nid . '/submission/' . $submission->sid, array('absolute' => TRUE));
......
3576 3593

  
3577 3594
/**
3578 3595
 * Set the necessary breadcrumb for the page we are on.
3596
 *
3597
 * @param object $node
3598
 *   The loaded webform node.
3599
 * @param boolean|object $submission
3600
 *   The submission if the current page is viewing or dealing with a submission,
3601
 *   or TRUE to just include the webform node in the breadcrumbs (used for
3602
 *   the submission completion confirmation page), or NULL for no extra
3603
 *   processing
3579 3604
 */
3580 3605
function webform_set_breadcrumb($node, $submission = NULL) {
3581
  $breadcrumb = drupal_get_breadcrumb();
3582

  
3583
  if (isset($node)) {
3584
    $webform_breadcrumb = array();
3585
    $webform_breadcrumb[] = empty($breadcrumb) ? l(t('Home'), '<front>') : array_shift($breadcrumb);
3586
    $webform_breadcrumb[] = l($node->title, 'node/' . $node->nid);
3587
    if (isset($submission)) {
3588
      $last_link = array_shift($breadcrumb);
3606
  $node_path = "node/{$node->nid}";
3607

  
3608
  // Set the href of the current menu item to be the node's path. This has two
3609
  // effects. The active trail will be to the node's prefered menu tree location,
3610
  // expanding the menu as appropriate. And the breadcrumbs will be set as if
3611
  // the current page were under the node's preferred location.
3612
  // Note that menu_tree_set_path() could be used to set the path for the menu,
3613
  // but it will not affect the breadcrumbs when the webform is not in the
3614
  // default menu.
3615
  menu_set_item(NULL, array('href' => $node_path) + menu_get_item());
3616

  
3617
  if ($submission) {
3618
    $breadcrumb = menu_get_active_breadcrumb();
3619

  
3620
    // Append the node title (or its menu name), in case it isn't in the path already.
3621
    $active_trail = menu_get_active_trail();
3622
    $last_active = end($active_trail);
3623
    $breadcrumb[] = $last_active['href'] === $node_path && !empty($last_active['in_active_trail'])
3624
                      ? l($last_active['title'], $node_path, $last_active['localized_options'])
3625
                      : l($node->title, $node_path);
3626

  
3627
    // Setting the current menu href will cause the submission title and current
3628
    // tab (if not the default tab) to be added to the active path when the
3629
    // webform is in the default location in the menu (node/NID). The title
3630
    // is desirable, but the tab name (e.g. Edit or Delete) isn't.
3631
    if (preg_match('/href=".*"/', end($breadcrumb), $matches)) {
3632
      foreach ($breadcrumb as $index => $link) {
3633
        if (stripos($link, $matches[0]) !== FALSE) {
3634
          $breadcrumb = array_slice($breadcrumb, 0, $index + 1);
3635
          break;
3636
        }
3637
      }
3638
    }
3639

  
3640
    // If the user is dealing with a submission, then the breadcrumb should
3641
    // be fudged to allow them to return to a likely list of webforms.
3642
    // Note that this isn't necessarily where they came from, but it's the
3643
    // best guess available.
3644
    if (is_object($submission)) {
3589 3645
      if (webform_results_access($node)) {
3590
        $webform_breadcrumb[] = l(t('Webform results'), 'node/' . $node->nid . '/webform-results');
3646
        $breadcrumb[] = l(t('Webform results'), $node_path . '/webform-results');
3591 3647
      }
3592 3648
      elseif (user_access('access own webform results')) {
3593
        $webform_breadcrumb[] = l(t('Submissions'), 'node/' . $node->nid . '/submissions');
3594
      }
3595
      if (isset($last_link)) {
3596
        $webform_breadcrumb[] = $last_link;
3649
        $breadcrumb[] = l(t('Submissions'), $node_path . '/submissions');
3597 3650
      }
3598 3651
    }
3599
    $breadcrumb = $webform_breadcrumb;
3600
  }
3601 3652

  
3602
  drupal_set_breadcrumb($breadcrumb);
3653
    drupal_set_breadcrumb($breadcrumb);
3654
  }
3603 3655
}
3604 3656

  
3605 3657
/**

Formats disponibles : Unified diff