Projet

Général

Profil

Paste
Télécharger (6,4 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / pathauto / API.txt @ 384fc62a

1 85ad3d82 Assos Assos
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('Content path settings')
50
patterndescr - The translated label for the default pattern (e.g.,
51
  t('Default path pattern (applies to all content types with blank patterns below)')
52
patterndefault - A translated default pattern (e.g., t('[cat]/[title].html'))
53
token_type - The token type (e.g. 'node', 'user') that can be used.
54
patternitems - For modules which need to express multiple patterns
55
  (for example, the node module supports a separate pattern for each
56
  content type), an array whose keys consist of identifiers for each
57
  pattern (e.g., the content type name) and values consist of the
58
  translated label for the pattern
59
bulkname - For modules which support a bulk update operation, the
60
  translated label for the action (e.g., t('Bulk update content paths'))
61
bulkdescr - For modules which support a bulk update operation, a
62
  translated, more thorough description of what the operation will do
63
  (e.g., t('Generate aliases for all existing content items which do not already have aliases.'))
64
65
66
==================
67
2 - $alias = pathauto_create_alias($module, $op, $placeholders, $src, $type=NULL)
68
==================
69
70
At the appropriate time (usually when a new item is being created for
71
which a generated alias is desired), call pathauto_create_alias() to
72
generate and create the alias.  See the user, taxonomy, and nodeapi hook
73
implementations in pathauto.module for examples.
74
75
$module - The name of your module (e.g., 'node')
76
$op - Operation being performed on the item ('insert', 'update', or
77
  'bulkupdate')
78
$placeholders - An array whose keys consist of the translated placeholders
79
  which appear in patterns and values are the "clean" values to be
80
  substituted into the pattern. Call pathauto_cleanstring() on any
81
  values which you do not know to be purely alphanumeric, to substitute
82
  any non-alphanumerics with the user's designated separator. Note that
83
  if the pattern has multiple slash-separated components (e.g., [term:path]),
84
  pathauto_cleanstring() should be called for each component, not the
85
  complete string.
86
  Example: $placeholders[t('[title]')] = pathauto_cleanstring($node->title);
87
$src - The "real" URI of the content to be aliased (e.g., "node/$node->nid")
88
$type - For modules which provided patternitems in hook_autopath(),
89
  the relevant identifier for the specific item to be aliased (e.g.,
90
  $node->type)
91
92
pathauto_create_alias() returns the alias that was created.
93
94
95
==================
96
3 - Bulk update function
97
==================
98
99
If a module supports bulk updating of aliases, it must provide a
100
function of this form, to be called by pathauto when the corresponding
101
checkbox is selected and the settings page submitted:
102
103
function <module>_pathauto_bulkupdate()
104
105
The function should iterate over the content items controlled by the
106
module, calling pathauto_create_alias() for each one. It is
107
recommended that the function report on its success (e.g., with a
108
count of created aliases) via drupal_set_message().
109
110
111
==================
112
4 - Bulk delete hook_path_alias_types()
113
==================
114
115
For modules that create new types of pages that can be aliased with pathauto, a
116
hook implementation is needed to allow the user to delete them all at once.
117
118
function hook_path_alias_types()
119
120
This hook returns an array whose keys match the beginning of the source paths
121
(e.g.: "node/", "user/", etc.) and whose values describe the type of page (e.g.:
122
"content", "users"). Like all displayed strings, these descriptionsshould be
123
localized with t(). Use % to match interior pieces of a path; "user/%/track". This
124
is a database wildcard, so be careful.
125
126
127
==================
128
Modules that extend node and/or taxonomy
129
==================
130
131
NOTE: this is basically not true any more.  If you feel you need this file an issue.
132
133
Many contributed Drupal modules extend the core node and taxonomy
134
modules. To extend pathauto patterns to support their extensions, they
135
may implement the pathauto_node and pathauto_taxonomy hooks.
136
137
To do so, implement the function <modulename>_pathauto_node (or _taxonomy),
138
accepting the arguments $op and $node (or $term). Two operations are
139
supported:
140
141
$op = 'placeholders' - return an array keyed on placeholder strings
142
(e.g., t('[eventyyyy]')) valued with descriptions (e.g. t('The year the
143
event starts.')).
144
$op = 'values' - return an array keyed on placeholder strings, valued
145
with the "clean" actual value for the passed node or category (e.g.,
146
pathauto_cleanstring(date('M', $eventstart)));
147
148
See contrib/pathauto_node_event.inc for an example of extending node
149
patterns.