1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Display Suite test module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_install().
|
10
|
*/
|
11
|
function ds_test_install() {
|
12
|
variable_set('ds_extras_region_to_block', TRUE);
|
13
|
variable_set('ds_extras_switch_view_mode', TRUE);
|
14
|
variable_set('ds_extras_hide_page_title', TRUE);
|
15
|
variable_set('ds_extras_field_template', TRUE);
|
16
|
variable_set('ds_extras_fields_extra', TRUE);
|
17
|
variable_set('ds_extras_hide_page_sidebars', TRUE);
|
18
|
variable_set('ds_extras_fields_extra_list', "node|article|ds_extras_extra_test_field\nnode|article|ds_extras_second_field");
|
19
|
variable_set('ds_extras_vd', TRUE);
|
20
|
|
21
|
db_update('system')
|
22
|
->fields(array('weight' => 2))
|
23
|
->condition('name', 'ds_test')
|
24
|
->execute();
|
25
|
}
|
26
|
|
27
|
/**
|
28
|
* Implements hook_views_api().
|
29
|
*/
|
30
|
function ds_test_views_api($module, $api) {
|
31
|
if ($module == 'views' && $api == 'views_default') {
|
32
|
return array('version' => 3);
|
33
|
}
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Helper function to return the tag name basid on tid.
|
38
|
*/
|
39
|
function ds_test_get_tag_name($raw_value, $object) {
|
40
|
$term = taxonomy_term_load($raw_value);
|
41
|
return $term->name;
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Helper function to return advanced view mode.
|
46
|
*/
|
47
|
function ds_views_row_adv_ds_testing($entity, $view_mode, $load_comments) {
|
48
|
return 'Advanced display for id ' . $entity->nid;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Implements hook_field_extra_fields().
|
53
|
*/
|
54
|
function ds_test_field_extra_fields() {
|
55
|
$extra = array();
|
56
|
|
57
|
// Register a single field to test that
|
58
|
// extra fields in the hidden region are really hidden.
|
59
|
$extra['node']['article']['display']['heavy_field'] = array(
|
60
|
'label' => t('Heavy extra test field'),
|
61
|
'weight' => 10,
|
62
|
);
|
63
|
|
64
|
return $extra;
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Implements hook_node_view().
|
69
|
*/
|
70
|
function ds_test_node_view($node, $view_mode, $langcode) {
|
71
|
$node->content['ds_extras_extra_test_field'] = array(
|
72
|
'#markup' => 'This is an extra field made available through "Extra fields" functionality.',
|
73
|
'#weight' => 10,
|
74
|
);
|
75
|
|
76
|
// Check whether the heavy extra field is rendered or not.
|
77
|
if ($node->type == 'article') {
|
78
|
$fields = field_extra_fields_get_display('node', 'article', $view_mode);
|
79
|
if (isset($fields['heavy_field']) && $fields['heavy_field']['visible']) {
|
80
|
$node->content['heavy_field'] = array(
|
81
|
'#markup' => 'Heavy field',
|
82
|
'#weight' => $fields['heavy_field']['weight'],
|
83
|
);
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Implements hook_ds_layout_info_alter().
|
90
|
*/
|
91
|
function ds_test_ds_layout_info_alter(&$layouts) {
|
92
|
unset($layouts['ds_3col_stacked_equal_width']);
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Implements hook_ds_fields_info().
|
97
|
*/
|
98
|
function ds_test_ds_fields_info($entity_type) {
|
99
|
if ($entity_type == 'node') {
|
100
|
$fields['node']['ds_test_field'] = array(
|
101
|
'title' => t('Test code field from hook'),
|
102
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
103
|
'function' => 'dstest_render_test_field',
|
104
|
);
|
105
|
$fields['node']['ds_test_field_2'] = array(
|
106
|
'title' => t('Test code field from hook 2'),
|
107
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
108
|
'function' => 'dstest_render_test_field',
|
109
|
);
|
110
|
$fields['node']['ds_test_field_empty_string'] = array(
|
111
|
'title' => t('Test code field that returns an empty string'),
|
112
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
113
|
'function' => 'dstest_render_empty_string',
|
114
|
);
|
115
|
$fields['node']['ds_test_field_false'] = array(
|
116
|
'title' => t('Test code field that returns FALSE'),
|
117
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
118
|
'function' => 'dstest_render_false',
|
119
|
);
|
120
|
$fields['node']['ds_test_field_null'] = array(
|
121
|
'title' => t('Test code field that returns NULL'),
|
122
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
123
|
'function' => 'dstest_render_null',
|
124
|
);
|
125
|
$fields['node']['ds_test_field_nothing'] = array(
|
126
|
'title' => t('Test code field that returns nothing'),
|
127
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
128
|
'function' => 'dstest_render_nothing',
|
129
|
);
|
130
|
$fields['node']['ds_test_field_zero_int'] = array(
|
131
|
'title' => t('Test code field that returns zero as an integer'),
|
132
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
133
|
'function' => 'dstest_render_zero_int',
|
134
|
);
|
135
|
$fields['node']['ds_test_field_zero_string'] = array(
|
136
|
'title' => t('Test code field that returns zero as a string'),
|
137
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
138
|
'function' => 'dstest_render_zero_string',
|
139
|
);
|
140
|
$fields['node']['ds_test_field_zero_float'] = array(
|
141
|
'title' => t('Test code field that returns zero as a floating point number'),
|
142
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
143
|
'function' => 'dstest_render_zero_float',
|
144
|
);
|
145
|
|
146
|
return $fields;
|
147
|
}
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Implements hook_ds_field_theme_functions_info().
|
152
|
*/
|
153
|
function ds_test_ds_field_theme_functions_info() {
|
154
|
return array('ds_test_theming_function' => t('Field test function'));
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* Theme field test function.
|
159
|
*/
|
160
|
function ds_test_theming_function($variables) {
|
161
|
return 'Testing field output through custom function';
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* Render the test code field.
|
166
|
*/
|
167
|
function dstest_render_test_field($field) {
|
168
|
return 'Test code field on node ' . $field['entity']->nid;
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* Test code field that returns an empty string.
|
173
|
*/
|
174
|
function dstest_render_empty_string() {
|
175
|
return '';
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* Test code field that returns FALSE.
|
180
|
*/
|
181
|
function dstest_render_false() {
|
182
|
return FALSE;
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* Test code field that returns NULL.
|
187
|
*/
|
188
|
function dstest_render_null() {
|
189
|
return NULL;
|
190
|
}
|
191
|
|
192
|
/**
|
193
|
* Test code field that returns nothing.
|
194
|
*/
|
195
|
function dstest_render_nothing() {
|
196
|
return;
|
197
|
}
|
198
|
|
199
|
/**
|
200
|
* Test code field that returns zero as an integer.
|
201
|
*/
|
202
|
function dstest_render_zero_int() {
|
203
|
return 0;
|
204
|
}
|
205
|
|
206
|
/**
|
207
|
* Test code field that returns zero as a string.
|
208
|
*/
|
209
|
function dstest_render_zero_string() {
|
210
|
return '0';
|
211
|
}
|
212
|
|
213
|
/**
|
214
|
* Test code field that returns zero as a floating point number.
|
215
|
*/
|
216
|
function dstest_render_zero_float() {
|
217
|
return 0.0;
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* Implements hook_ds_fields_info_alter().
|
222
|
*/
|
223
|
function ds_test_ds_fields_info_alter(&$fields, $entity_type) {
|
224
|
if (isset($fields['ds_test_field_2'])) {
|
225
|
$fields['ds_test_field_2']['title'] = 'Field altered';
|
226
|
}
|
227
|
}
|
228
|
|
229
|
/**
|
230
|
* Implements hook_ds_layouts_info().
|
231
|
*/
|
232
|
function ds_test_ds_layout_info() {
|
233
|
$path = drupal_get_path('module', 'ds_test');
|
234
|
$layouts = array(
|
235
|
'dstest_1col' => array(
|
236
|
'label' => t('Test One column'),
|
237
|
'path' => $path . '/dstest_1col',
|
238
|
'regions' => array(
|
239
|
'ds_content' => t('Content'),
|
240
|
),
|
241
|
),
|
242
|
'dstest_2col' => array(
|
243
|
'label' => t('Test Two column'),
|
244
|
'path' => $path . '/dstest_2col',
|
245
|
'regions' => array(
|
246
|
'left' => t('Left'),
|
247
|
'right' => t('Right')
|
248
|
),
|
249
|
'css' => TRUE,
|
250
|
),
|
251
|
);
|
252
|
|
253
|
return $layouts;
|
254
|
}
|
255
|
|
256
|
/**
|
257
|
* Implements hook_form_FORM_ID_alter().
|
258
|
*/
|
259
|
function ds_test_form_field_ui_display_overview_form_alter(&$form, &$form_state) {
|
260
|
foreach (element_children($form['fields']) as $key) {
|
261
|
if (isset($form['fields'][$key]['settings_edit'])) {
|
262
|
$settings = $form['fields'][$key]['settings_edit'];
|
263
|
if (!empty($settings)) {
|
264
|
$form['fields'][$key]['settings_edit']['#type'] = 'submit';
|
265
|
$form['fields'][$key]['settings_edit']['#value'] = 'edit ' . $key;
|
266
|
}
|
267
|
}
|
268
|
}
|
269
|
}
|
270
|
|
271
|
/**
|
272
|
* Implements hook_ds_pre_render_alter().
|
273
|
*/
|
274
|
function ds_test_ds_pre_render_alter(&$layout_render_array, $context) {
|
275
|
$entity = $context['entity'];
|
276
|
if (isset($entity->title) && $entity->title === 'Alter me!') {
|
277
|
$layout_render_array['left'][] = array('#markup' => 'cool!', '#weight' => 20);
|
278
|
}
|
279
|
}
|