Syndicate content

content management

Mark Jarrell's picture

Adding an Additional CCK Validation Function on a Field Using hook_form_alter

Although CCK automatically does some basic validation on your fields that you add to your Drupal content types, there are some cases where you'd like to do some additional validation for your site. One use case that I ran into recently was a basic text field that was being used to house hyperlinks for one of my websites. The text field had already been in place and working perfectly for months. Rather than do something drastic like replacing the field altogether with a field provided by the "Link" module, I decided to do a hook_form_alter to add in my own custom validation function.

Mark Jarrell's picture

Adding an .htaccess Rule to Make Simpler Links to Drupal Files

In a site I was recently working on, I found myself hard-coding links to files stored within my Drupal site's "files" directory. If you've ever coded these links before, you know that they normally look something like:
/sites/[sitename]/files/[someotherdirectory]/image.jpg

This can be somewhat painful to add to the site, especially if you have any plans to ever change the domain name of your site. It would really be ideal if you could leave the domain name out of the equation and just write the link in the format:
/files/[someotherdirectory]/image.jpg

This is actually possible to do using the .htaccess file that appears in the root of your Drupal installation. Basically you just need to add a single line:
RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]

After you implement this rule, you should be able to start writing simpler links to your "files" directory.

Happy coding!

Image of the rewrite rule and the alternate links. See PDF on DIWD Site.

Mark Jarrell's picture

Creating a Role-Based Menu in Drupal

I was working today on creating a menu that is role-based. This is for the new Jones International University (http://www.jiu.edu) content management system, which is going to be Drupal-based. I was a little surprised that you can't easily do this when you're creating your individual menu items (say who gets to see what), but it's actually not too hard with a bit of PHP code added into the theme layer (in your page.tpl.php file). The current header is shown in the screenshot below.