You are here

function webform_set_breadcrumb in Webform 7.4

Same name and namespace in other branches
  1. 6.3 webform.module \webform_set_breadcrumb()
  2. 7.3 webform.module \webform_set_breadcrumb()

Set the necessary breadcrumb for the page we are on.

Parameters

object $node: The loaded webform node.

bool|object $submission: The submission if the current page is viewing or dealing with a submission, or TRUE to just include the webform node in the breadcrumbs (used for the submission completion confirmation page), or NULL for no extra processing.

4 calls to webform_set_breadcrumb()
webform_submission_delete_form in includes/webform.submissions.inc
Confirm form to delete a single form submission.
webform_submission_page in includes/webform.submissions.inc
Menu callback; Present a Webform submission page for display or editing.
webform_submission_resend in includes/webform.submissions.inc
Form to resend specific e-mails associated with a submission.
_webform_confirmation in ./webform.module
Prints the confirmation message after a successful submission.

File

./webform.module, line 5028
This module provides a simple way to create forms and questionnaires.

Code

function webform_set_breadcrumb($node, $submission = NULL) {
  $node_path = "node/{$node->nid}";

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

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

    // Setting the current menu href will cause the submission title and current
    // tab (if not the default tab) to be added to the active path when the
    // webform is in the default location in the menu (node/NID). The title
    // is desirable, but the tab name (for example Edit or Delete) isn't.
    if (preg_match('/href=".*"/', end($breadcrumb), $matches)) {
      foreach ($breadcrumb as $index => $link) {
        if (stripos($link, $matches[0]) !== FALSE) {
          $breadcrumb = array_slice($breadcrumb, 0, $index + 1);
          break;
        }
      }
    }

    // If the user is dealing with a submission, then the breadcrumb should
    // be fudged to allow them to return to a likely list of webforms.
    // Note that this isn't necessarily where they came from, but it's the
    // best guess available.
    if (is_object($submission)) {
      if (webform_results_access($node)) {
        $breadcrumb[] = l(t('Webform results'), $node_path . '/webform-results');
      }
      elseif (user_access('access own webform results')) {
        $breadcrumb[] = l(t('Submissions'), $node_path . '/submissions');
      }
    }
    drupal_set_breadcrumb($breadcrumb);
  }
}