Projet

Général

Profil

Paste
Télécharger (13,3 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ds / ds.ds_fields_info.inc @ bf6fb0ee

1
<?php
2

    
3
/**
4
 * @file
5
 * Display Suite fields.
6
 */
7

    
8
/**
9
 * Implements hook_ds_fields_info().
10
 */
11
function ds_ds_fields_info($entity_type) {
12

    
13
  /* --------------------------------------------------------------
14
     Custom fields.
15
    -------------------------------------------------------------- */
16

    
17
  ctools_include('export');
18
  $custom_fields = ctools_export_crud_load_all('ds_fields');
19
  foreach ($custom_fields as $key => $field) {
20
    if (isset($field->entities[$entity_type])) {
21
      $fields[$entity_type][$key] = array(
22
        'title' => $field->label,
23
        'field_type' => $field->field_type,
24
        'properties' => $field->properties,
25
      );
26
      if (!empty($field->ui_limit)) {
27
        $lines = explode("\n", $field->ui_limit);
28
        $fields[$entity_type][$key]['ui_limit'] = $lines;
29
      }
30
    }
31
  }
32

    
33
  /* --------------------------------------------------------------
34
     General node fields.
35
    -------------------------------------------------------------- */
36

    
37
  // Node title.
38
  $fields['node']['title'] = array(
39
    'title' => t('Title'),
40
    'field_type' => DS_FIELD_TYPE_FUNCTION,
41
    'function' => 'ds_render_field',
42
    'properties' => array(
43
      'entity_render_key' => 'title',
44
      'settings' => array(
45
        'link' => array('type' => 'select', 'options' => array('no', 'yes')),
46
        'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
47
        'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
48
      ),
49
      'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
50
    )
51
  );
52

    
53
  // Links.
54
  $fields['node']['links'] = array(
55
    'title' => t('Links'),
56
    'field_type' => DS_FIELD_TYPE_IGNORE,
57
  );
58

    
59
  // Comments.
60
  if (module_exists('comment')) {
61
    $fields['node']['comments'] = array(
62
      'title' => t('Comments'),
63
      'field_type' => DS_FIELD_TYPE_IGNORE,
64
      'ui_limit' => array(
65
        '*|full', '*|default',
66
      ),
67
    );
68
  }
69

    
70
  // Node link.
71
  $fields['node']['node_link'] = array(
72
    'title' => t('Read more'),
73
    'field_type' => DS_FIELD_TYPE_FUNCTION,
74
    'function' => 'ds_render_field',
75
    'properties' => array(
76
      'settings' => array(
77
        'link text' => array('type' => 'textfield'),
78
        'link class' => array('type' => 'textfield', 'description' => t('Put a class on the link. Eg: btn btn-default')),
79
        'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
80
        'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
81
      ),
82
      'default' => array('link text' => 'Read more', 'link class' => '', 'wrapper' => '', 'class' => '', 'link' => 1),
83
    )
84
  );
85

    
86
  // Author.
87
  $fields['node']['author'] = array(
88
    'title' => t('Author'),
89
    'field_type' => DS_FIELD_TYPE_FUNCTION,
90
    'function' => 'ds_render_author_field',
91
    'properties' => array(
92
      'formatters' => array(
93
        'author' => t('Author'),
94
        'author_linked' => t('Author linked to profile')
95
      ),
96
    ),
97
  );
98

    
99
  // Created time.
100
  $format_types = system_get_date_types();
101
  $date_formatters = array();
102
  foreach ($format_types as $formatter) {
103
    $date_formatters['ds_post_date_' . $formatter['type']] = t($formatter['title']);
104
  }
105
  $fields['node']['post_date'] = array(
106
    'title' => t('Post date'),
107
    'field_type' => DS_FIELD_TYPE_FUNCTION,
108
    'function' => 'ds_render_date_field',
109
    'properties' => array(
110
      'formatters' => $date_formatters,
111
      'entity_render_key' => 'created',
112
    ),
113
  );
114

    
115
  // Updated time.
116
  $fields['node']['changed_date'] = array(
117
    'title' => t('Last modified'),
118
    'field_type' => DS_FIELD_TYPE_FUNCTION,
119
    'function' => 'ds_render_date_field',
120
    'properties' => array(
121
      'formatters' => $date_formatters,
122
      'entity_render_key' => 'changed',
123
    ),
124
  );
125

    
126
  // "Submitted by"-line. Skip this if the "Submitted By" module is used.
127
  if (!module_exists('submitted_by')) {
128
    $date_formatters = array('ds_time_ago' => t('Time ago')) + $date_formatters;
129
    $fields['node']['submitted_by'] = array(
130
      'title' => t('Submitted by'),
131
      'field_type' => DS_FIELD_TYPE_FUNCTION,
132
      'function' => 'ds_render_submitted_by',
133
      'properties' => array(
134
        'formatters' => $date_formatters,
135
      ),
136
    );
137
  }
138

    
139
  // User picture
140
  if (variable_get('user_pictures', 0)) {
141
    $key = 'user_picture';
142
    $type = DS_FIELD_TYPE_IGNORE;
143
    $picture_formatters = array();
144
    if (module_exists('image')) {
145
      $key = 'ds_user_picture';
146
      $type = DS_FIELD_TYPE_FUNCTION;
147
      $styles = image_styles();
148
      foreach ($styles as $formatter) {
149
        $picture_formatters['ds_picture_' . $formatter['name']] = drupal_ucfirst(str_replace('_', ' ', $formatter['name']));
150
      }
151
    }
152
    else {
153
      $picture_formatters['default'] = t('Default');
154
    }
155
    $fields['node'][$key] = array(
156
      'title' => t('User picture'),
157
      'field_type' => $type,
158
      'properties' => array(
159
        'formatters' => $picture_formatters,
160
      ),
161
    );
162
    if ($type == DS_FIELD_TYPE_FUNCTION) {
163
      $fields['node'][$key]['function'] = 'ds_render_user_picture';
164
    }
165
  }
166

    
167
  /* --------------------------------------------------------------
168
     Book support.
169
    -------------------------------------------------------------- */
170

    
171
  if (module_exists('book')) {
172

    
173
    $ui_limit = array();
174
    $types = variable_get('book_allowed_types', array('book'));
175
    foreach ($types as $type) {
176
      $ui_limit[] = $type . '|full';
177
    }
178

    
179
    if (!empty($ui_limit)) {
180
      $fields['node']['book_navigation'] = array(
181
        'title' => t('Book navigation'),
182
        'field_type' => DS_FIELD_TYPE_IGNORE,
183
        'ui_limit' => $ui_limit,
184
      );
185
    }
186
  }
187

    
188
  /* --------------------------------------------------------------
189
     Comment support.
190
    -------------------------------------------------------------- */
191

    
192
  if (module_exists('comment')) {
193

    
194
    // Comment Links.
195
    $fields['comment']['links'] = array(
196
      'title' => t('Links'),
197
      'field_type' => DS_FIELD_TYPE_IGNORE,
198
    );
199

    
200
    // Created time.
201
    $format_types = system_get_date_types();
202
    $date_formatters = array();
203
    foreach ($format_types as $formatter) {
204
      $date_formatters['ds_post_date_' . $formatter['type']] = t($formatter['title']);
205
    }
206
    $fields['comment']['post_date'] = array(
207
      'title' => t('Post date'),
208
      'field_type' => DS_FIELD_TYPE_FUNCTION,
209
      'function' => 'ds_render_date_field',
210
      'properties' => array(
211
        'formatters' => $date_formatters,
212
        'entity_render_key' => 'created',
213
      ),
214
    );
215

    
216
    // Permalink.
217
    $fields['comment']['permalink'] = array(
218
      'title' => t('Permalink'),
219
      'field_type' => DS_FIELD_TYPE_PREPROCESS,
220
    );
221

    
222
    // Submitted.
223
    $fields['comment']['submitted'] = array(
224
      'title' => t('Submitted'),
225
      'field_type' => DS_FIELD_TYPE_PREPROCESS,
226
    );
227

    
228
    // Title.
229
    $fields['comment']['title'] = array(
230
      'title' => t('Title'),
231
      'field_type' => DS_FIELD_TYPE_PREPROCESS,
232
    );
233

    
234
    // Author.
235
    $fields['comment']['author'] = array(
236
      'title' => t('Author'),
237
      'field_type' => DS_FIELD_TYPE_PREPROCESS,
238
    );
239

    
240
    // User signature.
241
    if (variable_get('user_signatures', 0)) {
242
      $fields['comment']['signature'] = array(
243
        'title' => t('User signature'),
244
        'field_type' => DS_FIELD_TYPE_PREPROCESS,
245
      );
246
    }
247

    
248
    // User picture
249
    if (variable_get('user_pictures', 0)) {
250
      $key = 'picture';
251
      $type = DS_FIELD_TYPE_PREPROCESS;
252
      $picture_formatters = array();
253
      if (module_exists('image')) {
254
        $key = 'ds_user_picture';
255
        $type = DS_FIELD_TYPE_FUNCTION;
256
        $styles = image_styles();
257
        foreach ($styles as $formatter) {
258
          $picture_formatters['ds_picture_' . $formatter['name']] = drupal_ucfirst(str_replace('_', ' ', $formatter['name']));
259
        }
260
      }
261
      else {
262
        $picture_formatters['default'] = t('Default');
263
      }
264
      $fields['comment'][$key] = array(
265
        'title' => t('User picture'),
266
        'field_type' => $type,
267
        'properties' => array(
268
          'formatters' => $picture_formatters,
269
        ),
270
      );
271
      if ($type == DS_FIELD_TYPE_FUNCTION) {
272
        $fields['comment'][$key]['function'] = 'ds_render_user_picture';
273
      }
274
    }
275
  }
276

    
277
  /* --------------------------------------------------------------
278
     User support.
279
    -------------------------------------------------------------- */
280

    
281
  // Username
282
  $fields['user']['name'] = array(
283
    'title' => t('Username'),
284
    'field_type' => DS_FIELD_TYPE_FUNCTION,
285
    'function' => 'ds_render_field',
286
    'properties' => array(
287
      'entity_render_key' => 'name',
288
      'settings' => array(
289
        'link' => array('type' => 'select', 'options' => array('no', 'yes')),
290
        'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
291
        'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
292
      ),
293
      'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
294
    )
295
  );
296

    
297
  // User signature
298
  if (variable_get('user_signatures', 0)) {
299
    $fields['user']['user_signature'] = array(
300
      'title' => t('User signature'),
301
      'field_type' => DS_FIELD_TYPE_FUNCTION,
302
      'function' => 'ds_render_markup',
303
      'properties' => array(
304
        'key' => 'signature',
305
        'format' => 'signature_format',
306
      ),
307
    );
308
  }
309

    
310
  // User picture
311
  if (variable_get('user_pictures', 0)) {
312
    $key = 'user_picture';
313
    $type = DS_FIELD_TYPE_IGNORE;
314
    $picture_formatters = array();
315
    if (module_exists('image')) {
316
      $key = 'ds_user_picture';
317
      $type = DS_FIELD_TYPE_FUNCTION;
318
      $styles = image_styles();
319
      foreach ($styles as $formatter) {
320
        $picture_formatters['ds_picture_' . $formatter['name']] = drupal_ucfirst(str_replace('_', ' ', $formatter['name']));
321
      }
322
    }
323
    else {
324
      $picture_formatters['default'] = t('Default');
325
    }
326
    $fields['user'][$key] = array(
327
      'title' => t('User picture'),
328
      'field_type' => $type,
329
      'properties' => array(
330
        'formatters' => $picture_formatters,
331
      ),
332
    );
333
    if ($type == DS_FIELD_TYPE_FUNCTION) {
334
      $fields['user'][$key]['function'] = 'ds_render_user_picture';
335
    }
336
  }
337

    
338
  /* --------------------------------------------------------------
339
     Taxonomy support.
340
    -------------------------------------------------------------- */
341

    
342
  if (module_exists('taxonomy')) {
343
    // Taxonomy term title.
344
    $fields['taxonomy_term']['title'] = array(
345
      'title' => t('Title'),
346
      'field_type' => DS_FIELD_TYPE_FUNCTION,
347
      'function' => 'ds_render_field',
348
      'properties' => array(
349
        'entity_render_key' => 'name',
350
        'settings' => array(
351
          'link' => array('type' => 'select', 'options' => array('no', 'yes')),
352
          'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
353
          'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
354
        ),
355
        'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
356
      )
357
    );
358

    
359
    // Taxonomy term link.
360
    $fields['taxonomy_term']['more_link'] = array(
361
      'title' => t('Read more'),
362
      'field_type' => DS_FIELD_TYPE_FUNCTION,
363
      'function' => 'ds_render_field',
364
      'properties' => array(
365
        'settings' => array(
366
          'link text' => array('type' => 'textfield'),
367
          'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
368
          'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
369
        ),
370
        'default' => array('link text' => 'Read more', 'wrapper' => '', 'class' => '', 'link' => 1),
371
      )
372
    );
373
  }
374

    
375
  // Support for ECK Entity title
376
  if (module_exists('eck')) {
377
    $entity_info = entity_get_info($entity_type);
378
    if (isset($entity_info['module']) && $entity_info['module'] == 'eck') {
379
      $fields[$entity_type]['title'] = array(
380
        'title' => t('Title'),
381
        'field_type' => DS_FIELD_TYPE_FUNCTION,
382
        'function' => 'ds_render_field',
383
        'properties' => array(
384
          'entity_render_key' => 'title',
385
          'settings' => array(
386
            'link' => array('type' => 'select', 'options' => array('no', 'yes')),
387
            'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
388
            'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
389
          ),
390
          'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
391
        )
392
      );
393
    }
394
  }
395

    
396
  // Support for fieldable panels panes.
397
  if (module_exists('fieldable_panels_panes')) {
398
    $fields['fieldable_panels_pane']['title_ds'] = array(
399
      'title' => t('Display Suite Title'),
400
      'field_type' => DS_FIELD_TYPE_FUNCTION,
401
      'function' => 'ds_render_field',
402
      'properties' => array(
403
        'entity_render_key' => 'title',
404
        'settings' => array(
405
          'link' => array('type' => 'select', 'options' => array('no', 'yes')),
406
          'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
407
          'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
408
        ),
409
        'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
410
      )
411
    );
412
  }
413

    
414
  if (isset($fields[$entity_type])) {
415
    return array($entity_type => $fields[$entity_type]);
416
  }
417
  return;
418
}