Hang on...

drupal_alter() example

Share |
This is a quick article about the drupal_alter() function using pathauto as an example.

In pathauto.inc, there is a drupal_alter('pathauto_alias', $alias, $context) call, so we can implement our own function to alter the alias generated by pathauto.

In our example module we need to create a new function, where the first part of the function name is the module name, "example_module", the second part is the string, "pathauto_alias", used in the drupal_alert call and the third part is the hook name, "alter". Arguments are (for Drupal 6) $data and $context.

 
/**
 * Implementing drupal_alter() hook to override pathauto alias
 */

function example_module_pathauto_alias_alter($data, $context){
 // you can do stuff with the data. No return required as $data is passed in by reference.
}

That's it. It is not very complicated. :)

Comments

thanks, but there's a typo

s/drupal_alert/drupal_alter/g

Also, is your comment textarea deliberately hidden?

Thanks for sharing this and I

Thanks for sharing this and I appreciate it.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <caption> <tbody> <tr> <td> <em> <b> <u> <i> <strong> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike>
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options