0

I have one Webform field call "Name". I use views to retrieve Webform result and edit link. I am using Path breadcrumbs module.

Example:

UserA - Edit
UserB - Edit
UserC - Edit

User A, B, and C had submitted the form. When I click edit, it will goes to their submission form where they can edit the info again.

When I click on the link, I hope breadcrumb will display "Name"

Example:

home > UserA
instead of
home > webform

home > UserB
instead of
home > webform

home > UserC
instead of
home > webform

Name is text. Link is not needed.

Can I add it to breadcrumb link title? How to do that?

9
  • @CodeNext, I had edited my question Commented Oct 12, 2016 at 8:18
  • let me clear again, "Name" is the title of your webform, so whenever anybody click on edit you wan form like Home>webform>Name, right? Or that Name is dynamic, means that Name has to be replaced by the USer name.
    – CodeNext
    Commented Oct 12, 2016 at 9:40
  • @CodeNext, Name is a textfield create for the weborm. When User A fill up the name field as Peter and later on click on edit, breadcrumb will be like home > Peter instead of home > webform Commented Oct 12, 2016 at 10:28
  • @CodeNext, any solution or cannot be done? Commented Oct 12, 2016 at 10:32
  • I think it is very difficult to do, why because the textfiled value goes to database, and to access that you have to access from the database and I am not getting the way how path breadcrumb module gets that. OTHER way, WHY YOU WANT TO ACHIEVE THIS USING BREADCRUMBS, Create a view-block and using the contextual filter you can get the webform result, if possible, and place that block in the region of breadcrumb and set its visibility as per url. So for that it will show Peter in that region like you want. This would be easy way, instead of going throuhg Path breadcrumbs module.
    – CodeNext
    Commented Oct 12, 2016 at 10:40

1 Answer 1

2

I was going to post something with Crumbs, but maybe you can start with something simpler:

I am trying to make this answer useful to different visitors who might have different ideas about their breadcrumb for webform submission pages.

Page access considerations

Do your visitors (those this is meant for) have access to pages like

  • node/28/submission/1/edit ? (I suppose the answer is yes)
  • node/28/submission/1 ? (Please check)

With hook_menu_alter()

I'm not sure what this does on a site without Crumbs enabled, but you can give it a try. This will change the page title / navigation title, which I think is used by core for building the breadcrumb.

This means if you had "Submission #1" as part of your breadcrumb, this will replace it with "Submission #2 by NAME".

Consider this code a stub. Especially the $submission->data[1][0]. This just happened to work for me, but might be different for you. devel dpm() is your friend!

/**
 * @param array[] $items
 */
function d7light_menu_alter(&$items) {

  if (!empty($items['node/%webform_menu/submission/%webform_menu_submission'])) {
    /* @see _d7light_webform_submission_title() */
    $items['node/%webform_menu/submission/%webform_menu_submission']['title callback'] = '_d7light_webform_submission_title';
  }
}

/**
 * @param object $node
 * @param object $submission
 *
 * @return string
 *
 * @see webform_submission_title()
 */
function _d7light_webform_submission_title($node, $submission) {

  if (empty($submission->data[1][0])) {
    return t('Submission #@serial', array('@serial' => $submission->serial));
  }

  return t(
    'Submission #@serial by @name',
    array(
      '@serial' => $submission->serial,
      // @todo Maybe something more generic than ->data[1][0]?
      '@name' => $submission->data[1][0],
    ));
}

With Easy Breadcrumb + hook_menu_alter()

Tbh I have only tested the code above with Crumbs enabled. So I don't know if it works without it.

I am also quite confident that it will work with Easy Breadcrumb, based on my understanding how it works.

With Crumbs + hook_menu_alter()

As said: You could try if enabling Crumbs makes a difference.

If you do, you might want to check admin/structure/crumbs/display and enable the "show current page".

With the Crumbs API.

This is an alternative to the method above, which does not change the page title but only the name in the breadcrumb.

Here is a starting point.

/**
 * A hook to register crumbs plugins.
 *
 * @param crumbs_InjectedAPI_hookCrumbsPlugins $api
 *   An object with methods to register plugins.
 *   See the class definition of crumbs_InjectedAPI_hookCrumbsPlugins, which
 *   methods are available.
 */
function MYMODULE_crumbs_plugins($api) {

  $api->routeTitleCallback(
    'node/%/submission/%',
    'webform_submission',
    function($path, array $item) {
      $node = $item['map'][1];
      $submission = $item['map'][3];
      if (0
        || !is_object($node)
        || !is_object($submission)
        || $node->type !== 'webform'
        || empty($submission->data[1][0])
      ) {
        return NULL;
      }
      $submission_name = $submission->data[1][0];
      return $item['title'] . ' (' . check_plain($submission_name) . ')';
    });
}

The same comment applies about $submission->data[1][0].

Changing the trail

Once you have tried those things, you can ask if you need more. I will then write more in this section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.