Project

General

Profile

Revision ebcc4118

Added by Assos Assos over 8 years ago

Weekly update of contrib modules

View differences:

drupal7/sites/all/modules/computed_field/computed_field.install
1 1
<?php
2

  
3 2
/**
4 3
 * @file
5 4
 * Install, update and uninstall functions for the computed field module.
6 5
 */
7 6

  
8 7
/**
9
 * Implements of hook_field_schema().
8
 * Implements hook_field_schema().
10 9
 */
11 10
function computed_field_field_schema($field) {
12 11
  if ($field['type'] == 'computed') {
13 12
    $settings = $field['settings'];
14
    
13

  
15 14
    if ($settings['store']) {
16 15
      $columns = array('value' => array());
17
      
18
      // Hardcoded 'longtext' settings
16

  
17
      // Hardcoded 'longtext' settings.
19 18
      if ($settings['database']['data_type'] == 'longtext') {
20 19
        $columns['value']['type'] = 'text';
21 20
        $columns['value']['size'] = 'big';
......
23 22
      else {
24 23
        $columns['value']['type'] = isset($settings['database']['data_type']) ? $settings['database']['data_type'] : 'varchar';
25 24
      }
26
      // 'text' and 'varchar' fields get length settings
25
      // 'text' and 'varchar' fields get length settings.
27 26
      if ($settings['database']['data_type'] == 'text' || $settings['database']['data_type'] == 'varchar') {
28 27
        $columns['value']['length'] = isset($settings['database']['data_length']) ? $settings['database']['data_length'] : 32;
29 28
      }
30
      // 'int' and 'float' fields get size settings
29
      // 'int' and 'float' fields get size settings.
31 30
      if ($settings['database']['data_type'] == 'int' || $settings['database']['data_type'] == 'float') {
32 31
        $columns['value']['size'] = isset($settings['database']['data_size']) ? $settings['database']['data_size'] : 'normal';
33 32
      }
34
      // 'decimal' fields get precision and scale settings
33
      // 'decimal' fields get precision and scale settings.
35 34
      if ($settings['database']['data_type'] == 'numeric') {
36 35
        $columns['value']['precision'] = isset($settings['database']['data_precision']) ? $settings['database']['data_precision'] : 10;
37 36
        $columns['value']['scale'] = isset($settings['database']['data_scale']) ? $settings['database']['data_scale'] : 2;
38 37
      }
39
      // Add 'not null' settings
38
      // Add 'not null' settings.
40 39
      $columns['value']['not null'] = isset($settings['database']['data_not_NULL']) ? $settings['database']['data_not_NULL'] : TRUE;
41
      // Add default values if set
42
      if ($settings['database']['data_default'] != '')  {
40
      // Add default values if set.
41
      if ($settings['database']['data_default'] !== '') {
43 42
        $columns['value']['default'] = $settings['database']['data_default'];
44 43
      }
45
      // Add a simple index on the data if requested (except 'text' fields)
46
      if ($settings['database']['data_index'] && $columns['value']['type'] != 'text')  {
47
         $indexes = array('value' => array('value'));
44
      // Add a simple index on the data if requested (except 'text' fields).
45
      if ($settings['database']['data_index'] && $columns['value']['type'] != 'text') {
46
        $indexes = array('value' => array('value'));
48 47
      }
49 48
    }
50 49
  }
51
  
50

  
52 51
  if (isset($columns) && isset($indexes)) {
53 52
    return array(
54 53
      'columns' => $columns,
......
60 59
      'columns' => $columns,
61 60
    );
62 61
  }
63
  else return;
62
  return;
64 63
}

Also available in: Unified diff