Delaware Web Designers – Inclind, Inc Internet Professionals | Inclind, Inc – Delaware Web Designers – Professional Delaware Web Design Since 1999

Sep/09

29

Clean Effective Programming

Using open source platforms such as Drupal to build an application stack on comes with its pro’s and con’s. The definite pro’s being that it is a CMS framework that is chameleon enough to work for any project, from small 3 page sites to very large commercial sites like Dogfish Head Craft Brewery, whereas other CMS packages like WordPress tend to be difficult to fit into a site that is more than just a blog (without lots of time intensive reverse engineering).

Although, sometimes the difficult part is working with some of the community developed modules. Though the community works hard, every now and then you will find that something won’t work exactly as intended and you’ll have to dive into the code. We’re no strangers to that, being custom website and web application developers.

One such module, Pathauto, a very useful and must-have module allows you to define URL schemas based on the content type (blog entry, page, image) which comes in handy for consistent URLs, not to mention great SEO positioning. It takes care of cleaning up URLs for you, so you can have nice URLs like blog/category/my-post.htm instead of blog?category=5&post_id=4 without having to work with .htaccess rewrite rules like you’d usually have to.

While architecting a new application for a client, I noticed URLs were being cut off. They were not long by any means. The URL that caught my eye looked like this:

explore/about-beracah/frequently-asked-questions/what-is-the-difference-between-a-modular-home-and-a-traditional-stick-built-hom

The rules that I had set in place obviously were not being adhered to. The URL should be this instead:

explore/about-beracah/frequently-asked-questions/what-is-the-difference-between-a-modular-home-and-a-traditional-stick-built-home.htm

See those last 5 characters (e.htm)? They need to be there. So, okay, I checked the settings to make sure there was no cap on the amount of characters I could have in a URL. While the Pathauto default is 128, you are free to up it as far as 999. I figure 300 should suffice for any website, so I put that in the config and hit save. I resave my page, and the URL does not change.

Hmm. My instincts told me two things:

  1. Either the database table field type is too small, or
  2. There is a hard limit in the code itself regardless of config

The first one was quicker to check. Looking in the database, the field that stores URLs is set as a VARCHAR(255), which should be enough. The next test was to change this entry manually right in the database and save. That part worked, and my URL was as it should be. Going to my page again and resaving, the URL was cut off. That’s when I knew it had to be limited in the code.

1 line in the module contains this code when determining max length of a URL:

$maxlength = min(variable_get(‘pathauto_max_component_length’, 100), 128);

What this code should say is your maxlength is equal to the number you set in the configuration. In my case, I chose 300. When the code executes however, something else happens. The min() function that is wrapped around the returned value will negate anything I have set as the limit, unless it is 128 or lower. The variable_get function is a simple function that looks for a value in the database based on the variable name, which is our character limit. If I did not set a value, it would return 100 as a default if pathauto_max_component_length was not set in the admin.

So, as you can see, when that evaluates, you get min(300,128), and min will return 128, as it is the lower value, hence, any URL could only ever be 128 characters long maximum. At this point, I knew the problem and all I simply had to do was remove the min() wrapping that statement and we were good to go, changing it to:

$maxlength = variable_get(‘pathauto_max_component_length’, 128);

That says, if a custom value is not defined, default to 128. Perfect for my intentions.

Just a small bump in the road working with open source code. A little bit of a geeky entry, but problem solving like this is fun for me.

Update: I have been told that this has been fixed in the latest development release of the module. :)

RSS Feed

No comments yet.

Leave a comment!

You must be logged in to post a comment.

<<

>>

Contact Us

Web: http://www.inclindinc.com
Phone: 302-856-2802
Email: info@inclind.com
Twitter: @inclindinc

About Us

Inclind Inc is a web development company on the east coast specializing in web design, web hosting, custom website design, website design, web applications, Coldfusion development, database design, MySQL / MSSQL database & consultation, PHP development, Wordpress themes, iPhone application development, Drupal hosting, Drupal development, Drupal module development, logo branding, business logic, custom application programming, Linux and Windows Server management and more.

Visit our website at inclind.com

Theme Design by devolux.org
delaware's premiere web design and development company. serving delaware, maryland, pennsylvania and beyond.
delaware web design - delaware website design - delaware web development - maryland web design - maryland website design - maryland web development - ocean city maryland web design - philadelphia web design - philadelphia web designers - washington dc web development - washington dc web design - custom drupal templates - drupal module development - custom drupal modules - custom drupal development - drupal ubercart support - drupal ecommerce