1 |
85ad3d82
|
Assos Assos
|
<?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 |
4f315dab
|
Assos Assos
|
/**
|
28 |
|
|
* Implements hook_theme_registry_alter().
|
29 |
|
|
*/
|
30 |
|
|
function ds_test_theme_registry_alter(&$theme_registry) {
|
31 |
|
|
|
32 |
|
|
// Inject ds_entity_variables in all entity theming functions.
|
33 |
|
|
$entity_info = entity_get_info();
|
34 |
|
|
foreach ($entity_info as $entity => $info) {
|
35 |
|
|
if (isset($entity_info[$entity]['fieldable']) && $entity_info[$entity]['fieldable']) {
|
36 |
|
|
|
37 |
|
|
// User uses user_profile for theming.
|
38 |
|
|
if ($entity == 'user') $entity = 'user_profile';
|
39 |
|
|
|
40 |
|
|
// Only add preprocess functions if entity exposes theme function.
|
41 |
|
|
if (isset($theme_registry[$entity])) {
|
42 |
|
|
$theme_registry[$entity]['preprocess functions'][] = 'ds_test_entity_variables';
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
// Support for File Entity.
|
48 |
|
|
if (isset($theme_registry['file_entity'])) {
|
49 |
|
|
$theme_registry['file_entity']['preprocess functions'][] = 'ds_test_entity_variables';
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
// Support for Entity API.
|
53 |
|
|
if (isset($theme_registry['entity'])) {
|
54 |
|
|
$theme_registry['entity']['preprocess functions'][] = 'ds_test_entity_variables';
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
/**
|
59 |
|
|
* Theming function, added after ds_entity_variables().
|
60 |
|
|
*
|
61 |
|
|
* @param $variables
|
62 |
|
|
*/
|
63 |
|
|
function ds_test_entity_variables(&$variables) {
|
64 |
|
|
if (isset($_GET['store'])) {
|
65 |
|
|
cache_set('ds_test', $variables);
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
85ad3d82
|
Assos Assos
|
/**
|
70 |
|
|
* Implements hook_views_api().
|
71 |
|
|
*/
|
72 |
|
|
function ds_test_views_api($module, $api) {
|
73 |
|
|
if ($module == 'views' && $api == 'views_default') {
|
74 |
|
|
return array('version' => 3);
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/**
|
79 |
|
|
* Helper function to return the tag name basid on tid.
|
80 |
|
|
*/
|
81 |
|
|
function ds_test_get_tag_name($raw_value, $object) {
|
82 |
|
|
$term = taxonomy_term_load($raw_value);
|
83 |
|
|
return $term->name;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* Helper function to return advanced view mode.
|
88 |
|
|
*/
|
89 |
|
|
function ds_views_row_adv_ds_testing($entity, $view_mode, $load_comments) {
|
90 |
|
|
return 'Advanced display for id ' . $entity->nid;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
/**
|
94 |
|
|
* Implements hook_field_extra_fields().
|
95 |
|
|
*/
|
96 |
|
|
function ds_test_field_extra_fields() {
|
97 |
|
|
$extra = array();
|
98 |
|
|
|
99 |
|
|
// Register a single field to test that
|
100 |
|
|
// extra fields in the hidden region are really hidden.
|
101 |
|
|
$extra['node']['article']['display']['heavy_field'] = array(
|
102 |
|
|
'label' => t('Heavy extra test field'),
|
103 |
|
|
'weight' => 10,
|
104 |
|
|
);
|
105 |
|
|
|
106 |
|
|
return $extra;
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
/**
|
110 |
|
|
* Implements hook_node_view().
|
111 |
|
|
*/
|
112 |
|
|
function ds_test_node_view($node, $view_mode, $langcode) {
|
113 |
|
|
$node->content['ds_extras_extra_test_field'] = array(
|
114 |
|
|
'#markup' => 'This is an extra field made available through "Extra fields" functionality.',
|
115 |
|
|
'#weight' => 10,
|
116 |
|
|
);
|
117 |
|
|
|
118 |
|
|
// Check whether the heavy extra field is rendered or not.
|
119 |
|
|
if ($node->type == 'article') {
|
120 |
|
|
$fields = field_extra_fields_get_display('node', 'article', $view_mode);
|
121 |
|
|
if (isset($fields['heavy_field']) && $fields['heavy_field']['visible']) {
|
122 |
|
|
$node->content['heavy_field'] = array(
|
123 |
|
|
'#markup' => 'Heavy field',
|
124 |
|
|
'#weight' => $fields['heavy_field']['weight'],
|
125 |
|
|
);
|
126 |
|
|
}
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
/**
|
131 |
|
|
* Implements hook_ds_layout_info_alter().
|
132 |
|
|
*/
|
133 |
|
|
function ds_test_ds_layout_info_alter(&$layouts) {
|
134 |
|
|
unset($layouts['ds_3col_stacked_equal_width']);
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
/**
|
138 |
|
|
* Implements hook_ds_fields_info().
|
139 |
|
|
*/
|
140 |
|
|
function ds_test_ds_fields_info($entity_type) {
|
141 |
|
|
if ($entity_type == 'node') {
|
142 |
|
|
$fields['node']['ds_test_field'] = array(
|
143 |
|
|
'title' => t('Test code field from hook'),
|
144 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
145 |
|
|
'function' => 'dstest_render_test_field',
|
146 |
|
|
);
|
147 |
|
|
$fields['node']['ds_test_field_2'] = array(
|
148 |
|
|
'title' => t('Test code field from hook 2'),
|
149 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
150 |
|
|
'function' => 'dstest_render_test_field',
|
151 |
|
|
);
|
152 |
|
|
$fields['node']['ds_test_field_empty_string'] = array(
|
153 |
|
|
'title' => t('Test code field that returns an empty string'),
|
154 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
155 |
|
|
'function' => 'dstest_render_empty_string',
|
156 |
|
|
);
|
157 |
|
|
$fields['node']['ds_test_field_false'] = array(
|
158 |
|
|
'title' => t('Test code field that returns FALSE'),
|
159 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
160 |
|
|
'function' => 'dstest_render_false',
|
161 |
|
|
);
|
162 |
|
|
$fields['node']['ds_test_field_null'] = array(
|
163 |
|
|
'title' => t('Test code field that returns NULL'),
|
164 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
165 |
|
|
'function' => 'dstest_render_null',
|
166 |
|
|
);
|
167 |
|
|
$fields['node']['ds_test_field_nothing'] = array(
|
168 |
|
|
'title' => t('Test code field that returns nothing'),
|
169 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
170 |
|
|
'function' => 'dstest_render_nothing',
|
171 |
|
|
);
|
172 |
|
|
$fields['node']['ds_test_field_zero_int'] = array(
|
173 |
|
|
'title' => t('Test code field that returns zero as an integer'),
|
174 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
175 |
|
|
'function' => 'dstest_render_zero_int',
|
176 |
|
|
);
|
177 |
|
|
$fields['node']['ds_test_field_zero_string'] = array(
|
178 |
|
|
'title' => t('Test code field that returns zero as a string'),
|
179 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
180 |
|
|
'function' => 'dstest_render_zero_string',
|
181 |
|
|
);
|
182 |
|
|
$fields['node']['ds_test_field_zero_float'] = array(
|
183 |
|
|
'title' => t('Test code field that returns zero as a floating point number'),
|
184 |
|
|
'field_type' => DS_FIELD_TYPE_FUNCTION,
|
185 |
|
|
'function' => 'dstest_render_zero_float',
|
186 |
|
|
);
|
187 |
|
|
|
188 |
|
|
return $fields;
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/**
|
193 |
|
|
* Implements hook_ds_field_theme_functions_info().
|
194 |
|
|
*/
|
195 |
|
|
function ds_test_ds_field_theme_functions_info() {
|
196 |
|
|
return array('ds_test_theming_function' => t('Field test function'));
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
/**
|
200 |
|
|
* Theme field test function.
|
201 |
|
|
*/
|
202 |
|
|
function ds_test_theming_function($variables) {
|
203 |
|
|
return 'Testing field output through custom function';
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
/**
|
207 |
|
|
* Render the test code field.
|
208 |
|
|
*/
|
209 |
|
|
function dstest_render_test_field($field) {
|
210 |
|
|
return 'Test code field on node ' . $field['entity']->nid;
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
/**
|
214 |
|
|
* Test code field that returns an empty string.
|
215 |
|
|
*/
|
216 |
|
|
function dstest_render_empty_string() {
|
217 |
|
|
return '';
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
/**
|
221 |
|
|
* Test code field that returns FALSE.
|
222 |
|
|
*/
|
223 |
|
|
function dstest_render_false() {
|
224 |
|
|
return FALSE;
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
/**
|
228 |
|
|
* Test code field that returns NULL.
|
229 |
|
|
*/
|
230 |
|
|
function dstest_render_null() {
|
231 |
|
|
return NULL;
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
/**
|
235 |
|
|
* Test code field that returns nothing.
|
236 |
|
|
*/
|
237 |
|
|
function dstest_render_nothing() {
|
238 |
|
|
return;
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
/**
|
242 |
|
|
* Test code field that returns zero as an integer.
|
243 |
|
|
*/
|
244 |
|
|
function dstest_render_zero_int() {
|
245 |
|
|
return 0;
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
/**
|
249 |
|
|
* Test code field that returns zero as a string.
|
250 |
|
|
*/
|
251 |
|
|
function dstest_render_zero_string() {
|
252 |
|
|
return '0';
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
/**
|
256 |
|
|
* Test code field that returns zero as a floating point number.
|
257 |
|
|
*/
|
258 |
|
|
function dstest_render_zero_float() {
|
259 |
|
|
return 0.0;
|
260 |
|
|
}
|
261 |
|
|
|
262 |
|
|
/**
|
263 |
|
|
* Implements hook_ds_fields_info_alter().
|
264 |
|
|
*/
|
265 |
|
|
function ds_test_ds_fields_info_alter(&$fields, $entity_type) {
|
266 |
|
|
if (isset($fields['ds_test_field_2'])) {
|
267 |
|
|
$fields['ds_test_field_2']['title'] = 'Field altered';
|
268 |
|
|
}
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
/**
|
272 |
|
|
* Implements hook_ds_layouts_info().
|
273 |
|
|
*/
|
274 |
|
|
function ds_test_ds_layout_info() {
|
275 |
|
|
$path = drupal_get_path('module', 'ds_test');
|
276 |
|
|
$layouts = array(
|
277 |
|
|
'dstest_1col' => array(
|
278 |
|
|
'label' => t('Test One column'),
|
279 |
|
|
'path' => $path . '/dstest_1col',
|
280 |
|
|
'regions' => array(
|
281 |
|
|
'ds_content' => t('Content'),
|
282 |
|
|
),
|
283 |
|
|
),
|
284 |
|
|
'dstest_2col' => array(
|
285 |
|
|
'label' => t('Test Two column'),
|
286 |
|
|
'path' => $path . '/dstest_2col',
|
287 |
|
|
'regions' => array(
|
288 |
|
|
'left' => t('Left'),
|
289 |
|
|
'right' => t('Right')
|
290 |
|
|
),
|
291 |
|
|
'css' => TRUE,
|
292 |
|
|
),
|
293 |
|
|
);
|
294 |
|
|
|
295 |
|
|
return $layouts;
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
/**
|
299 |
|
|
* Implements hook_form_FORM_ID_alter().
|
300 |
|
|
*/
|
301 |
|
|
function ds_test_form_field_ui_display_overview_form_alter(&$form, &$form_state) {
|
302 |
|
|
foreach (element_children($form['fields']) as $key) {
|
303 |
|
|
if (isset($form['fields'][$key]['settings_edit'])) {
|
304 |
|
|
$settings = $form['fields'][$key]['settings_edit'];
|
305 |
|
|
if (!empty($settings)) {
|
306 |
|
|
$form['fields'][$key]['settings_edit']['#type'] = 'submit';
|
307 |
|
|
$form['fields'][$key]['settings_edit']['#value'] = 'edit ' . $key;
|
308 |
|
|
}
|
309 |
|
|
}
|
310 |
|
|
}
|
311 |
|
|
}
|
312 |
|
|
|
313 |
|
|
/**
|
314 |
|
|
* Implements hook_ds_pre_render_alter().
|
315 |
|
|
*/
|
316 |
|
|
function ds_test_ds_pre_render_alter(&$layout_render_array, $context) {
|
317 |
|
|
$entity = $context['entity'];
|
318 |
|
|
if (isset($entity->title) && $entity->title === 'Alter me!') {
|
319 |
|
|
$layout_render_array['left'][] = array('#markup' => 'cool!', '#weight' => 20);
|
320 |
|
|
}
|
321 |
|
|
} |