-
Notifications
You must be signed in to change notification settings - Fork 0
/
word_link.actions.inc
212 lines (201 loc) · 5.72 KB
/
word_link.actions.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* @file
* Actions for the Word Link module.
*/
/**
* Action function.
*
* Goes through values and uses them to modify the passed words by
* replacing the existing values.
*/
function word_link_modify_action($word, $context) {
$modify = array_filter($context['modify']);
foreach ($modify as $name => $value) {
$value = $context['properties'][$name];
$word->$name = $value;
}
word_link_save($word);
if ($context['progress']['current'] >= $context['progress']['total']) {
word_link_clear_filter_cache();
}
}
/**
* Action function.
*
* Delete words.
*/
function word_link_delete_action($word, $context) {
word_link_delete($word->id);
if ($context['progress']['current'] >= $context['progress']['total']) {
word_link_clear_filter_cache();
}
}
/**
* Action form function.
*
* Displays form elements for properties of word.
*/
function word_link_modify_action_form($context, &$form_state) {
$properties = array(
'weight',
'case_sensitive',
'url',
'url_title',
'class',
'rel',
'visibility',
'except_list',
'status',
);
$form['#tree'] = TRUE;
$form['modify'] = array(
'#type' => 'fieldset',
'#title' => t('Choose what to change'),
);
foreach ($properties as $property) {
$form['modify'][$property] = array(
'#type' => 'checkbox',
'#title' => t(
'@title',
array(
'@title' => drupal_ucfirst(str_replace('_', ' ', $property)),
)
),
);
}
$form['properties'] = array(
'#type' => 'container',
);
$form['properties']['weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight'),
'#size' => 3,
'#maxlength' => 3,
'#description' => t('Weight of the word. Lighter weights are higher up, heavier weights go down.'),
'#states' => array(
'invisible' => array(
':input[name="modify[weight]"]' => array('checked' => FALSE),
),
),
);
$form['properties']['case_sensitive'] = array(
'#type' => 'checkbox',
'#title' => t('Case Sensitivity'),
'#description' => t('By default Word Link are case sensitive. Uncheck this checkbox if you want this particular Word Link to be case insensitive.'),
'#states' => array(
'invisible' => array(
':input[name="modify[case_sensitive]"]' => array('checked' => FALSE),
),
),
);
$form['properties']['url'] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('The URL of the page to link to. External links must start with %http or %https and will be open in new window.', array('%http' => 'http://', '%https' => 'https://')),
'#autocomplete_path' => 'word-link/ajax/urls',
'#states' => array(
'invisible' => array(
':input[name="modify[url]"]' => array('checked' => FALSE),
),
),
);
$form['properties']['url_title'] = array(
'#type' => 'textfield',
'#title' => t('URL Title'),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('Title for the above URL. It will be embedded in the created link and appear as a tooltip when hovering the mouse over the link.'),
'#states' => array(
'invisible' => array(
':input[name="modify[url_title]"]' => array('checked' => FALSE),
),
),
);
$form['properties']['class'] = array(
'#type' => 'textfield',
'#title' => t('Class'),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('Use this to add a class for the link. Default value is "word-link".'),
'#states' => array(
'invisible' => array(
':input[name="modify[class]"]' => array('checked' => FALSE),
),
),
);
$form['properties']['rel'] = array(
'#type' => 'textfield',
'#title' => t('Relationship'),
'#size' => 30,
'#maxlength' => 30,
'#description' => t('Use this to add a rel attribute to the link.'),
'#states' => array(
'invisible' => array(
':input[name="modify[rel]"]' => array('checked' => FALSE),
),
),
);
$form['properties']['visibility'] = array(
'#type' => 'radios',
'#title' => t('Show links on specific pages'),
'#options' => array(
t('All pages except those listed'),
t('Only the listed pages'),
),
'#default_value' => 0,
'#states' => array(
'invisible' => array(
':input[name="modify[visibility]"]' => array('checked' => FALSE),
),
),
);
$form['properties']['except_list'] = array(
'#type' => 'textarea',
'#description' => t('Specify pages by using their paths. Enter one path per line. E.g. node/1.'),
'#states' => array(
'invisible' => array(
':input[name="modify[except_list]"]' => array('checked' => FALSE),
),
),
);
$form['properties']['status'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#description' => t('If unchecked this word will not be converted.'),
'#default_value' => 1,
'#states' => array(
'invisible' => array(
':input[name="modify[status]"]' => array('checked' => FALSE),
),
),
);
return $form;
}
/**
* Action form submit function.
*
* Passes values to word_link_modify().
*/
function word_link_modify_action_submit($form, $form_state) {
return array(
'modify' => $form_state['values']['modify'],
'properties' => $form_state['values']['properties'],
);
}
/**
* Action function.
*
* Checks if word URL is valid and if not change word status to disabled.
*/
function word_link_disable_invalid_word_action($word, &$context) {
if (!word_link_valid_path(drupal_get_normal_path($word->url))) {
$word->status = FALSE;
word_link_save($word);
}
if ($context['progress']['current'] >= $context['progress']['total']) {
word_link_clear_filter_cache();
}
}