I've just started to use this module, and now I am stuck without knowing how to make breadcrumbs for some pages that are not content, taxonomy or views.

More precisely I need to make crumbs for pages based on the "blog/130" pattern, where 130 is a user ID. This system path isn't a view, so I have to use custom paths to get to it. Using pathauto, I've turned these "blog/[uid]" paths into "forum/blogs/[username]".

Assuming that I can catch the right URL's with the wildcard character, how do I access variables for the specific user in the title and path fields? Using PHP I could extract these based on the URL, but I can't really pass any variables on to the title/path fields where I need them?!

Am I just missing something, or could this module need support for passing variables from the PHP field on to the title/path fields?

Comments

MGN’s picture

Category: feature » support

When you say they are not "content" do you mean they are not nodes? It seems like they ought to be nodes, and if they are you can setup the breadcrumb using the custom_breadcrumbs module - just click on the 'node' tab at /admin/build/custom_breadcrumbs and pick the "blog" node type.

(I could be wrong on the types of pages you are creating, so if you are not using the core blog module, explain how you are creating these "blog" pages, what contrib module you are using etc.)

If [username] refers to the page's author, you should be able to get what you are looking for by using some of the following tokens:

[author-uid] Node author's user id
[author-name] Node author's user name

I think there are other ways (using tokens for custom fields, profile fields, etc.) to do this. Perhaps other users can contribute their suggestions.

Am I just missing something, or could this module need support for passing variables from the PHP field on to the title/path fields?

The breadcrumb visibility field accepts php just to determine whether a given breadcrumb should be displayed or not. It wasn't intended for the use you are suggesting. But generally this module manages to accomplish the same thing by using tokens (i.e. write the php to deliver the token, then use the token in custom breadcrumbs, and other modules). Note that you can also develop your own tokens using the Token starter kit.

rsm08’s picture

The pages I'm referring to aren't nodes. They're just pages created by custom functions. The "blog/[uid]" path is created by the core blog module I think, and the returned page isn't related to any specific node - it just displays a list of node teasers.

When no node is in the context, the tokens are unusable. Nobody knows that the number in the path is a uid, so the user tokens aren't available.

Anyway, tokens are though novice friendly a very cumbersome way to accomplish things. I can't figure out on top of my head how to make tokens based on pathauto url parts, and it seems to me that it would be easier to make a separate function that re-writes the breadcrumbs for these pages. But this could be avoided if your module made the url parts available. It should be fairly easy to implement.

I know that right now the php field is only for figuring out whether to re-write the breadcrumb, but why not give it more function by allowing it to pass a value to use in the re-written url?

MGN’s picture

One possible feature (disabled by default, and only for roles assigned use php in custom breadcrumbs privledges) would be to allow php in the titles and paths (rather than trying to do it in the breadcrumb visibility section). Here is the idea (Drafted for the README.txt file):

Use PHP in breadcrumb titles and paths
----------------------------------
If this advanced option is enabled at admin/settings/custom-breadcrumbs, then users given 
'use php in custom breadcrumbs' permission can include php code snippets in the titles and/or
paths fields of the add breadcrumb form. When defined, appropriate objects such as $node, $term, or $view, will be available for use in these code snippets. Be careful when enabling this option, since the incorrect use of php can break your site. Note that for most users the preferred method is to create new tokens as needed using the tokenSTARTER.module included in the token module. 

But for those who would rather just write php directly within custom breadcrumbs, there are a couple of ways to use php to define breadcrumb paths and titles. 

1. Enter a php code snippet to return an array of breadcrumb titles in the titles text field and a corresponding array of breadcrumb paths in the paths text field, such as

Titles:
return array('title-1','title-2','title-3');

Paths:
return array('path/to/title-1','path/to/title-2','path/to/title-3');

2. Sometimes it may be more convenient to assign the titles and paths in the same code snippet, so
you can also return an associative array with elements 'titles' and 'paths' that contain the
titles and paths arrays, respectively. For example,

Titles:
$titles = array('title-1','title-2','title-3');
$paths = array('path/to/title-1','path/to/title-2','path/to/title-3');
return array('titles' => $titles, 'paths' => $paths);

(In this case, the paths text field will be ignored, so you can leave it empty). 

Note that if this option is enabled and an array is not returned, then the module defaults to the standard  operation of using each line of the titles and paths text fields to define a part of the breadcrumb.

Does this approach sound like it would be useful? Is there a better way? I am currently testing this, but thought I should check to see if this makes sense before moving it into 6.x-2.x-dev for testing.

MGN’s picture

Title: Returning variables for use in path with PHP » Provide an option to use PHP in titles and paths
Component: custom_breadcrumbs_paths » custom_breadcrumbs
Category: support » feature
Status: Active » Fixed

I've now implemented this in custom_breadcrumbs 6.x-2.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.