Hi,

I'm new to Custom Breadcrumbs, but I can't see an answer to this one...

I'm trying to set the visibility based on a user role, but I can't get the code to work properly.

I've got:

<?php global $user;
if in_array('staff member',$user->roles){
return false;
}else{
return true;
} ?>

with a normal ('authenticated user') the subsequent breadcrumb should appear, but it doesn't.

What am I doing wrong?

Comments

MGN’s picture

Don't include the php tags in the breadcrumb visibility field (its assumed for this field), and put parentheses around in_array and it should work

global $user;
if (in_array('staff member',$user->roles)){
return false;
}else{
return true;
}
gmak’s picture

Ah, so simple and yet...

Maybe the instruction text below the visibility field should explain that the php tags are not necessary. That seems contrary to most other fields where you can input php code (like the titles and paths fields on the same form).

Thanks for your help.

MGN’s picture

I agree, the documentation needs to be more explicit. I'll get that into the next commit.

gmak’s picture

Just wanted to say, documentation issues aside, this is a great module. The more I understand it's use, the more it's making my site infinitely more usable.

Thanks for all your hard work!

MGN’s picture

Status: Active » Fixed

Thanks. #872926: Field description for Breadcrumb Visibility with PHP. is another request for the updated documentation. I'll go ahead and mark this issue as fixed, and follow up on that issue.

Status: Fixed » Closed (fixed)

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

khosman’s picture

I've just started running the latest dev version (as opposed to the beta listed above) - and I'm not seeing any note "not to include" opening/closing php tags. It took me a lot of time before figuring this out and it'd be a great time-saver to include for people just discovering this module. I see this thread is nearly a year old now. Has the fix been included in some other version I'm not seeing?

MGN’s picture

Thanks. I found three places where these instructions were missing from the UI (custom_breadcrumbs_views, _panels, and api), so I suspect you are not seeing the note when creating a custom breadcrumb of one of these types. But you should see it when creating any of the other types (node, path, taxonomy). The fix has now been committed to 6.x-2.x-dev.