1 | <?php |
---|
2 | /** |
---|
3 | * @file |
---|
4 | * Installation file for the Term Fields Ente Planificador module |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * Implements hook_install(). |
---|
9 | */ |
---|
10 | function ente_planificador_term_fields_install() { |
---|
11 | // It is time now to alter the {term_fields_term} schema if necessary. |
---|
12 | $ret = array(); |
---|
13 | // Load the dependent Taxonomy module, in case it has been disabled. |
---|
14 | drupal_load('module', 'taxonomy'); |
---|
15 | module_load_include('inc', 'term_fields', 'term_fields.admin'); |
---|
16 | |
---|
17 | // Create the forum vocabulary if it does not exist. |
---|
18 | $vocabulary = taxonomy_vocabulary_load(variable_get('ente_ubicacion_vocabulary', 0)); |
---|
19 | if (!$vocabulary) { |
---|
20 | $edit = array( |
---|
21 | 'name' => t('Ubicación'), |
---|
22 | 'machine_name' => 'ubicacion', |
---|
23 | 'description' => t('Lista de Entidades, municipios y parroquias de Venezuela'), |
---|
24 | 'hierarchy' => 1, |
---|
25 | 'module' => 'ente_planificador', |
---|
26 | 'weight' => -10, |
---|
27 | ); |
---|
28 | $vocabulary = $edit; |
---|
29 | taxonomy_save_vocabulary($vocabulary); |
---|
30 | variable_set('ente_ubicacion_vocabulary', $vocabulary['vid']); |
---|
31 | $vocabulary = (object) $vocabulary; |
---|
32 | } |
---|
33 | |
---|
34 | //create field codigo |
---|
35 | $field_code_geo = array( |
---|
36 | 'fid' => 'codigo_geo_localizacion', |
---|
37 | 'title' => 'Codigo', |
---|
38 | 'description' => '', |
---|
39 | 'required' => 0, |
---|
40 | 'weight' => 0, |
---|
41 | 'type' => 'text', |
---|
42 | 'options' => array( |
---|
43 | 'default' => array( |
---|
44 | 'value' => '', |
---|
45 | ), |
---|
46 | 'max_length' => '', |
---|
47 | 'size' => '', |
---|
48 | ), |
---|
49 | 'widget' => 'textfield', |
---|
50 | 'vid' => $vocabulary->vid, |
---|
51 | ); |
---|
52 | |
---|
53 | $field = (object) $field_code_geo; |
---|
54 | $field->options = array(); |
---|
55 | $field->module = 'ente_planificador_term_fields'; |
---|
56 | |
---|
57 | if ($field_info = term_fields_get_fields_info($field->type)) { |
---|
58 | $field->module = $field_info['module']; |
---|
59 | } |
---|
60 | else { |
---|
61 | drupal_set_message(t('An error occured while saving the new field %title (%field). If such error persists, please contact a site administrator.', array('%title' => $field->title, '%field' => $field->fid)), 'error'); |
---|
62 | return; |
---|
63 | } |
---|
64 | |
---|
65 | // Flag the fiels as instantiated. |
---|
66 | if (empty($field->instantiated)) { |
---|
67 | $field->instantiated = 1; |
---|
68 | } |
---|
69 | |
---|
70 | drupal_write_record('term_fields', $field); |
---|
71 | |
---|
72 | drupal_write_record('term_fields', $field, array('fid')); |
---|
73 | drupal_write_record('term_fields_instance', $field, array('fid', 'vid')); |
---|
74 | |
---|
75 | // Get the new columns if any. |
---|
76 | $columns = module_invoke($field->module, 'term_fields_api', 'storage', $field); |
---|
77 | |
---|
78 | //add new field in table |
---|
79 | if (!db_column_exists('term_fields_term', $field->fid)) { |
---|
80 | $name = 'codigo_geo_localizacion_value'; |
---|
81 | foreach ($columns as $column) { |
---|
82 | db_add_field($ret, 'term_fields_term', $name, $column); |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | /* |
---|
88 | * Implementation of hook_uninstall |
---|
89 | */ |
---|
90 | function ente_planificador_term_fields_uninstall() { |
---|
91 | // Load the dependent Taxonomy module, in case it has been disabled. |
---|
92 | variable_del('ente_ubicacion_vocabulary'); |
---|
93 | } |
---|
94 | |
---|