Projet

Général

Profil

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

root / drupal7 / sites / all / modules / rules / modules / path.rules.inc @ 950416da

1
<?php
2

    
3
/**
4
 * @file
5
 * Rules integration for the path module.
6
 *
7
 * @addtogroup rules
8
 *
9
 * @{
10
 */
11

    
12
/**
13
 * Implements hook_rules_file_info() on behalf of the path module.
14
 */
15
function rules_path_file_info() {
16
  return array('modules/path.eval');
17
}
18

    
19
/**
20
 * Implements hook_rules_action_info() on behalf of the path module.
21
 */
22
function rules_path_action_info() {
23
  return array(
24
    'path_alias' => array(
25
      'label' => t('Create or delete any URL alias'),
26
      'group' => t('Path'),
27
      'parameter' => array(
28
        'source' => array(
29
          'type' => 'text',
30
          'label' => t('Existing system path'),
31
          'description' => t('Specifies the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.') . ' ' . t('Leave it empty to delete URL aliases pointing to the given path alias.'),
32
          'optional' => TRUE,
33
        ),
34
        'alias' => array(
35
          'type' => 'text',
36
          'label' => t('URL alias'),
37
          'description' => t('Specify an alternative path by which this data can be accessed. For example, "about" for an about page. Use a relative path and do not add a trailing slash.') . ' ' . t('Leave it empty to delete URL aliases pointing to the given system path.'),
38
          'optional' => TRUE,
39
          'cleaning callback' => 'rules_path_clean_replacement_values',
40
        ),
41
        'language' => array(
42
          'type' => 'token',
43
          'label' => t('Language'),
44
          'description' => t('If specified, the language for which the URL alias applies.'),
45
          'options list' => 'entity_metadata_language_list',
46
          'optional' => TRUE,
47
          'default value' => LANGUAGE_NONE,
48
        ),
49
      ),
50
      'base' => 'rules_action_path_alias',
51
      'callbacks' => array('dependencies' => 'rules_path_dependencies'),
52
      'access callback' => 'rules_path_integration_access',
53
    ),
54
    'node_path_alias' => array(
55
      'label' => t("Create or delete a content's URL alias"),
56
      'group' => t('Path'),
57
      'parameter' => array(
58
        'node' => array(
59
          'type' => 'node',
60
          'label' => t('Content'),
61
          'save' => TRUE,
62
        ),
63
        'alias' => array(
64
          'type' => 'text',
65
          'label' => t('URL alias'),
66
          'description' => t('Specify an alternative path by which the content can be accessed. For example, "about" for an about page. Use a relative path and do not add a trailing slash.') . ' ' . t('Leave it empty to delete the URL alias.'),
67
          'optional' => TRUE,
68
          'cleaning callback' => 'rules_path_clean_replacement_values',
69
        ),
70
      ),
71
      'base' => 'rules_action_node_path_alias',
72
      'callbacks' => array('dependencies' => 'rules_path_dependencies'),
73
      'access callback' => 'rules_path_integration_access',
74
    ),
75
    'taxonomy_term_path_alias' => array(
76
      'label' => t("Create or delete a taxonomy term's URL alias"),
77
      'group' => t('Path'),
78
      'parameter' => array(
79
        'node' => array(
80
          'type' => 'taxonomy_term',
81
          'label' => t('Taxonomy term'),
82
          'save' => TRUE,
83
        ),
84
        'alias' => array(
85
          'type' => 'text',
86
          'label' => t('URL alias'),
87
          'description' => t('Specify an alternative path by which the term can be accessed. For example, "content/drupal" for a Drupal term. Use a relative path and do not add a trailing slash.') . ' ' . t('Leave it empty to delete the URL alias.'),
88
          'optional' => TRUE,
89
          'cleaning callback' => 'rules_path_clean_replacement_values',
90
        ),
91
      ),
92
      'base' => 'rules_action_node_path_alias',
93
      'callbacks' => array('dependencies' => 'rules_path_dependencies'),
94
      'access callback' => 'rules_path_integration_access',
95
    ),
96
  );
97
}
98

    
99
/**
100
 * Callback to specify the path module as dependency.
101
 */
102
function rules_path_dependencies() {
103
  return array('path');
104
}
105

    
106
/**
107
 * Path integration access callback.
108
 */
109
function rules_path_integration_access($type, $name) {
110
  if ($type == 'action' && $name == 'path_alias') {
111
    return user_access('administer url aliases');
112
  }
113
  return user_access('create url aliases');
114
}
115

    
116
/**
117
 * Implements hook_rules_condition_info() on behalf of the path module.
118
 */
119
function rules_path_condition_info() {
120
  return array(
121
    'path_has_alias' => array(
122
      'label' => t('Path has URL alias'),
123
      'group' => t('Path'),
124
      'parameter' => array(
125
        'source' => array(
126
          'type' => 'text',
127
          'label' => t('Existing system path'),
128
          'description' => t('Specifies the existing path you wish to check for. For example: node/28, forum/1, taxonomy/term/1+2.'),
129
          'optional' => TRUE,
130
        ),
131
        'language' => array(
132
          'type' => 'token',
133
          'label' => t('Language'),
134
          'description' => t('If specified, the language for which the URL alias applies.'),
135
          'options list' => 'entity_metadata_language_list',
136
          'optional' => TRUE,
137
          'default value' => LANGUAGE_NONE,
138
        ),
139
      ),
140
      'base' => 'rules_condition_path_has_alias',
141
      'callbacks' => array('dependencies' => 'rules_path_dependencies'),
142
      'access callback' => 'rules_path_integration_access',
143
    ),
144
    'path_alias_exists' => array(
145
      'label' => t('URL alias exists'),
146
      'group' => t('Path'),
147
      'parameter' => array(
148
        'alias' => array(
149
          'type' => 'text',
150
          'label' => t('URL alias'),
151
          'description' => t('Specify the URL alias to check for. For example, "about" for an about page.'),
152
          'optional' => TRUE,
153
          'cleaning callback' => 'rules_path_clean_replacement_values',
154
        ),
155
        'language' => array(
156
          'type' => 'token',
157
          'label' => t('Language'),
158
          'description' => t('If specified, the language for which the URL alias applies.'),
159
          'options list' => 'entity_metadata_language_list',
160
          'optional' => TRUE,
161
          'default value' => LANGUAGE_NONE,
162
        ),
163
      ),
164
      'base' => 'rules_condition_path_alias_exists',
165
      'callbacks' => array('dependencies' => 'rules_path_dependencies'),
166
      'access callback' => 'rules_path_integration_access',
167
    ),
168
  );
169
}
170

    
171
/**
172
 * @}
173
 */