Both 'paths' and 'titles' input is limited to approx 245 characters.
Therefore, if I enter any PHP code longer than that, it trims my code to the first 244 characters.
It seems to come from custom_breadcrumbs.install line 32.
it sets the type 'varchar' for column 'titles' , limited to 255 chars (limitation prior to mysql 5.03).
should we change this column type to 'text'? what about the 'paths' column?

Comments

MGN’s picture

Thanks for bringing this up.

I realized this might be a problem when I added the php in titles and paths option. I didn't switch the column type to text because I was concerned about the possible performance hit. And varchar size is appropriate for the default titles and paths when not using the php option. I wouldn't want to make that change without carefully benchmarking the code before and after.

I have found that you can actually fit a lot of php code in this space if you write compact code. If it takes much more, another approach would be to create a custom token.

barraponto’s picture

i worked around this issue using a custom function, instead of a custom token.
i guess custom token would be the best practice in these cases (since i could call it [node-breadcrumb])
but it is kind of odd on the usability side.

MGN’s picture

Category: bug » feature
Status: Active » Postponed

Good idea....choice of token or a custom function just comes down to how you intend to use it. Given that php for titles and paths is an advanced feature, I would rather not modify the database structure to better accommodate it at this time.

I am marking this as postponed to be re-activated when other database changes are being considered.

kevinquillen’s picture

How are you supposed to write a solid php snippet if you are limited to 255 characters?

For example, this just -barely- makes it in:

$url_path = explode('/', $_SERVER['REQUEST_URI']); if (is_array($url_path)) { foreach($url_path as $path) { if ($path != 'index.htm') { $title = ucwords(str_replace('-', ' ', $path)); $titles[] = $title; } } } return $titles;

I had to make it all one line. For Paths, I can't vary that snippet at all as its too long.

Maybe I am misunderstanding Custom Breadcrumbs, but I needed a breadcrumb for a node type that neither has a menu entry, and its termpath points to a url alias (NAT/aliasing setup).

MGN’s picture

How are you supposed to write a solid php snippet if you are limited to 255 characters?

See comments #1-3 above. To reiterate, this advanced option was never intended for lengthy scripts and the preferred way to do this is to use tokens where possible. If you need to, you can include a longer script in an .inc file and start your snippet with a require_once() function to load the include file.

This was also discussed in #694184: Problems using PHP in Titles and Paths for node

Can you explain what you are trying to do with the script?

MGN’s picture

How are you supposed to write a solid php snippet if you are limited to 255 characters?

See comments #1-3 above. This was also discussed in #694184: Problems using PHP in Titles and Paths for node. To reiterate, this advanced option was never intended for lengthy scripts and the preferred way to do this is to use tokens where possible. If you need to, you can write a function to perform the operation, include it in an .inc file, and start your snippet with a require_once() function to load the include file.

Can you explain what you are trying to do with the script?

redndahead’s picture

Using the require_once() method works, but just as an fyi for other people I had to put the return outside of the include file.

willvincent’s picture

redndahead: can you explain how you're getting this to work with a require_once? I've tried that and get no results.. with the return statement outside of the include.

I've gotten it working temporarily by changing the DB schema to use mediumtext on the title fields, which it probably should be if custom php is allowed, alternatively, if custom php is going to be allowed, it should be more clear that there is a size limit, and preferred methods of implementation provided for longer snippets, or a clear way to easily include a file.

My use case is that I have nodes with multiple taxonomy terms, from different vocabs. I want the breadcrumb to display the term from only one specific vocab, but taxonomy tokens don't allow for this -- at least not that I can see.

redndahead’s picture

@tcindie This probably won't match exactly what you want, but this will show you how I use the require_once

This is what I put in custom breadcrumbs in the Titles box:

<?php
  $path = drupal_get_path('theme', 'my-theme');
  require_once $path . '/taxonomy-view-breadcrumb.inc';
  return $values;
?>

This is what is in taxonomy-view-breadcrumb.inc:

<?php
  $values['titles'][] = 'Guides';
  $values['paths'][] = 'guides';
  $parents = taxonomy_get_parents_all(arg(2));
  $parent_total = count($parents) - 1;

  for ($i=$parent_total; $i>0; $i--) {
    $values['titles'][] = $parents[$i]->name;
    $values['paths'][] = drupal_get_path_alias('taxonomy/term/' . $parents[$i]->tid);    
  }
  $values['titles'][] = $parents[0]->name;
  $values['paths'][] = '<none>';
kevinquillen’s picture

'My use case is that I have nodes with multiple taxonomy terms, from different vocabs. I want the breadcrumb to display the term from only one specific vocab, but taxonomy tokens don't allow for this -- at least not that I can see.'

Same as me.

eliza411’s picture

Component: Code » Documentation
Category: feature » task

It would be nice if the character limit were mentioned in the field descriptions and/or the README file. If that's not already in the works, I can write it up and submit it as a patch.

eliza411’s picture

Component: Documentation » Code
Category: task » feature

I wasn't supposed to change those settings from the original issue. Setting them back. Sorry about that.

MGN’s picture

@eliza411, Thanks for the suggestion. I've included this information in the field descriptions and the readme file. In the readme file I've also referenced this page as an example of how to include longer code snippets. Committed to 6.x-2.x-dev http://drupal.org/cvs?commit=370346

enkara’s picture

Waiting for the next stable release that solves this problem

JimNastic’s picture

Hi redndahead,

Great example! Thanks!
Actually, I think I might be trying to do something very similar!

I have a taxonomy called region, associated with a node called region using Node Auto Term. On the "Region" node page, I want to show the following breadcrumbs:
Home>GrandparentRegion>ParentRegion>ThisRegion

Additionally, I have a node type called House. Each node can be associated with multiple Region term. On a "House" node page, I'd to show the following breadcrumbs:
Home>RegionA|RegionB|RegionC>ThisHouse

So if I understand correctly, the main difference to your code is that after I lookup the taxonomy terms, I need to show the path to the region node, rather than the region taxonomy term.

So my questions:
* Do you have any tips how would build breadcrumbs pointing to the associated node, rather than the taxonomy term page?
* Do you paste anything in the "Path" field in custom breadcrumbs?

Finally, to check I understand your code correctly,
* The first two lines in the inc file creates a link to a page called "guides", which will always be the first breadcrumb
* The next two lines, and for loop, creates a series of links to every parent term.
* The last two lines creates a breadcrumb, without link, to the current term.
Is that correct?

Thanks again for your code, I'd really appreciate feedback if you can find a moment!

Cheers,
Jim

JimNastic’s picture

Here is an example creating custom breadcrumbs based on nat_ng associated taxonomy terms. This allows you to use a taxonomy to organize the relationship between pages but always display links to node pages.

<?php

  $node = node_load(arg(1));
  $tids = array_keys($node->nat_ng);

  $parents = taxonomy_get_parents_all($tids[0]);
  $parent_total = count($parents) - 1;
  
  if ($parent_total > 0) {
    for ($i=$parent_total; $i>0; $i--) {
      $values['titles'][] = $parents[$i]->name;
      $tid=$parents[$i]->tid;
      $nid = array_keys(nat_ng_get_nids(array($tid)));
      $values['paths'][] = drupal_get_path_alias('node/' . $nid[0]);    
    }
  }                            
  $values['titles'][] = $parents[0]->name;
  $values['paths'][] = '<none>';
barraponto’s picture

@KevinQuillen @redndahead :

there is no need for a require_once. you might as well define the function in a custom module, then just call it.
it will save you from the extra work a require_once needs. it is also good for two reasons:

  • it helps keeping the code in database a minimal, which i see as good practice.
  • before every function, you can comment where it is being called, keeping documentation up for later debugging.

i have also found that making your own tokens is quite easy. give a good read to the Token STARTERKIT that comes with the token module.

lamp5’s picture

Issue summary: View changes
Status: Postponed » Closed (outdated)