| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | This document explains how to provide "Pathauto integration" in amodule. You need this if you would like to provide additional tokensor if your module has paths and you wish to have them automaticallyaliased.  The simplest integration is just to provide tokens so wecover that first.  More advanced integration requires animplementation of hook_pathauto to provide a settings form.It may be helpful to review some examples of integration from thepathauto_node.inc, pathauto_taxonomy.inc, and pathauto_user.inc files.==================1 - Providing additional tokens==================If all you want is to enable tokens for your module you will simplyneed to implement two functions:  hook_token_values  hook_token_listSee the token.module and it's API.txt for more information about thisprocess.If the token is intended to generate a path expected to contain slashes,the token name must end in 'path', 'path-raw' or 'alias'. This indicates toPathauto that the slashes should not be removed from the replacement value.When an object is created (whether it is a node or a user or ataxonomy term) the data that Pathauto hands to the token_values in the$object is in a specific format. This is the format that most peoplewrite code to handle. However, during edits and bulk updates the datamay be in a totally different format. So, if you are writing ahook_token_values implementation to add special tokens, be sure totest creation, edit, and bulk update cases to make sure your code willhandle it.==================2 - Settings hook - To create aliases for your module==================You must implement hook_pathauto($op), where $op is always (at thistime) 'settings'. Return an object (NOT an array) containing thefollowing members, which will be used by pathauto to build a groupof settings for your module and define the variables for saving yoursettings:module - The name of your module (e.g., 'node')groupheader - The translated label for the settings group (e.g.,  t('Content path settings')patterndescr - The translated label for the default pattern (e.g.,  t('Default path pattern (applies to all content types with blank patterns below)')patterndefault - A translated default pattern (e.g., t('[cat]/[title].html'))token_type - The token type (e.g. 'node', 'user') that can be used.patternitems - For modules which need to express multiple patterns  (for example, the node module supports a separate pattern for each  content type), an array whose keys consist of identifiers for each  pattern (e.g., the content type name) and values consist of the  translated label for the patternbulkname - For modules which support a bulk update operation, the  translated label for the action (e.g., t('Bulk update content paths'))bulkdescr - For modules which support a bulk update operation, a  translated, more thorough description of what the operation will do  (e.g., t('Generate aliases for all existing content items which do not already have aliases.'))==================2 - $alias = pathauto_create_alias($module, $op, $placeholders, $src, $type=NULL)==================At the appropriate time (usually when a new item is being created forwhich a generated alias is desired), call pathauto_create_alias() togenerate and create the alias.  See the user, taxonomy, and nodeapi hookimplementations in pathauto.module for examples.$module - The name of your module (e.g., 'node')$op - Operation being performed on the item ('insert', 'update', or  'bulkupdate')$placeholders - An array whose keys consist of the translated placeholders  which appear in patterns and values are the "clean" values to be  substituted into the pattern. Call pathauto_cleanstring() on any  values which you do not know to be purely alphanumeric, to substitute  any non-alphanumerics with the user's designated separator. Note that  if the pattern has multiple slash-separated components (e.g., [term:path]),  pathauto_cleanstring() should be called for each component, not the  complete string.  Example: $placeholders[t('[title]')] = pathauto_cleanstring($node->title);$src - The "real" URI of the content to be aliased (e.g., "node/$node->nid")$type - For modules which provided patternitems in hook_autopath(),  the relevant identifier for the specific item to be aliased (e.g.,  $node->type)pathauto_create_alias() returns the alias that was created.==================3 - Bulk update function==================If a module supports bulk updating of aliases, it must provide afunction of this form, to be called by pathauto when the correspondingcheckbox is selected and the settings page submitted:function <module>_pathauto_bulkupdate()The function should iterate over the content items controlled by themodule, calling pathauto_create_alias() for each one. It isrecommended that the function report on its success (e.g., with acount of created aliases) via drupal_set_message().==================4 - Bulk delete hook_path_alias_types()==================For modules that create new types of pages that can be aliased with pathauto, ahook implementation is needed to allow the user to delete them all at once.function hook_path_alias_types()This hook returns an array whose keys match the beginning of the source paths(e.g.: "node/", "user/", etc.) and whose values describe the type of page (e.g.:"content", "users"). Like all displayed strings, these descriptionsshould belocalized with t(). Use % to match interior pieces of a path; "user/%/track". Thisis a database wildcard, so be careful.==================Modules that extend node and/or taxonomy==================NOTE: this is basically not true any more.  If you feel you need this file an issue.Many contributed Drupal modules extend the core node and taxonomymodules. To extend pathauto patterns to support their extensions, theymay implement the pathauto_node and pathauto_taxonomy hooks.To do so, implement the function <modulename>_pathauto_node (or _taxonomy),accepting the arguments $op and $node (or $term). Two operations aresupported:$op = 'placeholders' - return an array keyed on placeholder strings(e.g., t('[eventyyyy]')) valued with descriptions (e.g. t('The year theevent starts.')).$op = 'values' - return an array keyed on placeholder strings, valuedwith the "clean" actual value for the passed node or category (e.g.,pathauto_cleanstring(date('M', $eventstart)));See contrib/pathauto_node_event.inc for an example of extending nodepatterns.
 |