[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/pathauto/ -> API.txt (source)

   1  This document explains how to provide "Pathauto integration" in a
   2  module. You need this if you would like to provide additional tokens
   3  or if your module has paths and you wish to have them automatically
   4  aliased.  The simplest integration is just to provide tokens so we
   5  cover that first.  More advanced integration requires an
   6  implementation of hook_pathauto to provide a settings form.
   7  
   8  It may be helpful to review some examples of integration from the
   9  pathauto_node.inc, pathauto_taxonomy.inc, and pathauto_user.inc files.
  10  
  11  
  12  ==================
  13  1 - Providing additional tokens
  14  ==================
  15  
  16  If all you want is to enable tokens for your module you will simply
  17  need to implement two functions:
  18  
  19    hook_token_values
  20    hook_token_list
  21  
  22  See the token.module and it's API.txt for more information about this
  23  process.
  24  
  25  If the token is intended to generate a path expected to contain slashes,
  26  the token name must end in 'path', 'path-raw' or 'alias'. This indicates to
  27  Pathauto that the slashes should not be removed from the replacement value.
  28  
  29  When an object is created (whether it is a node or a user or a
  30  taxonomy term) the data that Pathauto hands to the token_values in the
  31  $object is in a specific format. This is the format that most people
  32  write code to handle. However, during edits and bulk updates the data
  33  may be in a totally different format. So, if you are writing a
  34  hook_token_values implementation to add special tokens, be sure to
  35  test creation, edit, and bulk update cases to make sure your code will
  36  handle it.
  37  
  38  ==================
  39  2 - Settings hook - To create aliases for your module
  40  ==================
  41  You must implement hook_pathauto($op), where $op is always (at this
  42  time) 'settings'. Return an object (NOT an array) containing the
  43  following members, which will be used by pathauto to build a group
  44  of settings for your module and define the variables for saving your
  45  settings:
  46  
  47  module - The name of your module (e.g., 'node')
  48  groupheader - The translated label for the settings group (e.g.,
  49    t('Node path settings')
  50  patterndescr - The translated label for the default pattern (e.g.,
  51    t('Default path pattern (applies to all node types with blank patterns below)')
  52  patterndefault - A translated default pattern (e.g., t('[cat]/[title].html'))
  53  placeholders - An array whose keys consist of the translated placeholders
  54    which will appear in patterns (e.g., t('[title]')) and values are
  55    the translated description of the placeholders (e.g.,
  56    t('The title of the node, with spaces and punctuation.')
  57  patternitems - For modules which need to express multiple patterns
  58    (for example, the node module supports a separate pattern for each
  59    node type), an array whose keys consist of identifiers for each
  60    pattern (e.g., the node type name) and values consist of the
  61    translated label for the pattern
  62  supportsfeeds - Modules which support RSS feeds should set this to the
  63    string that's appended to a path for its feed (usually 'feed') , so
  64    when administrators enable "Create feed aliases" an alias for this
  65    content type's feed will be generated in addition to the base alias.
  66  bulkname - For modules which support a bulk update operation, the
  67    translated label for the action (e.g., t('Bulk update node paths'))
  68  bulkdescr - For modules which support a bulk update operation, a
  69    translated, more thorough description of what the operation will do
  70    (e.g., t('Generate aliases for all existing nodes which do not already have aliases.'))
  71  
  72  
  73  ==================
  74  2 - $alias = pathauto_create_alias($module, $op, $placeholders, $src, $type=NULL)
  75  ==================
  76  
  77  At the appropriate time (usually when a new item is being created for
  78  which a generated alias is desired), call pathauto_create_alias() to
  79  generate and create the alias.  See the user, taxonomy, and nodeapi hook
  80  implementations in pathauto.module for examples.
  81  
  82  $module - The name of your module (e.g., 'node')
  83  $op - Operation being performed on the item ('insert', 'update', or
  84    'bulkupdate')
  85  $placeholders - An array whose keys consist of the translated placeholders
  86    which appear in patterns and values are the "clean" values to be
  87    substituted into the pattern. Call pathauto_cleanstring() on any
  88    values which you do not know to be purely alphanumeric, to substitute
  89    any non-alphanumerics with the user's designated separator. Note that
  90    if the pattern has multiple slash-separated components (e.g., [catpath]),
  91    pathauto_cleanstring() should be called for each component, not the
  92    complete string.
  93    Example: $placeholders[t('[title]')] = pathauto_cleanstring($node->title);
  94  $src - The "real" URI of the content to be aliased (e.g., "node/$node->nid")
  95  $type - For modules which provided patternitems in hook_autopath(),
  96    the relevant identifier for the specific item to be aliased (e.g.,
  97    $node->type)
  98  
  99  pathauto_create_alias() returns the alias that was created.
 100  
 101  
 102  ==================
 103  3 - Bulk update function
 104  ==================
 105  
 106  If a module supports bulk updating of aliases, it must provide a
 107  function of this form, to be called by pathauto when the corresponding
 108  checkbox is selected and the settings page submitted:
 109  
 110  function <module>_pathauto_bulkupdate()
 111  
 112  The function should iterate over the content items controlled by the
 113  module, calling pathauto_create_alias() for each one. It is
 114  recommended that the function report on its success (e.g., with a
 115  count of created aliases) via drupal_set_message().
 116  
 117  
 118  ==================
 119  4 - Bulk delete hook_path_alias_types()
 120  ==================
 121  
 122  For modules that create new types of pages that can be aliased with pathauto, a
 123  hook implementation is needed to allow the user to delete them all at once.
 124  
 125  function hook_path_alias_types()
 126  
 127  This hook returns an array whose keys match the beginning of the source paths
 128  (e.g.: "node/", "user/", etc.) and whose values describe the type of page (e.g.:
 129  "content", "users"). Like all displayed strings, these descriptionsshould be
 130  localized with t(). Use % to match interior pieces of a path; "user/%/track". This
 131  is a database wildcard, so be careful.
 132  
 133  
 134  ==================
 135  Modules that extend node and/or taxonomy
 136  ==================
 137  
 138  NOTE: this is basically not true any more.  If you feel you need this file an issue.
 139  
 140  Many contributed Drupal modules extend the core node and taxonomy
 141  modules. To extend pathauto patterns to support their extensions, they
 142  may implement the pathauto_node and pathauto_taxonomy hooks.
 143  
 144  To do so, implement the function <modulename>_pathauto_node (or _taxonomy),
 145  accepting the arguments $op and $node (or $term). Two operations are
 146  supported:
 147  
 148  $op = 'placeholders' - return an array keyed on placeholder strings
 149  (e.g., t('[eventyyyy]')) valued with descriptions (e.g. t('The year the
 150  event starts.')).
 151  $op = 'values' - return an array keyed on placeholder strings, valued
 152  with the "clean" actual value for the passed node or category (e.g.,
 153  pathauto_cleanstring(date('M', $eventstart)));
 154  
 155  See contrib/pathauto_node_event.inc for an example of extending node
 156  patterns.


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7