-
Notifications
You must be signed in to change notification settings - Fork 0
/
hosting_environment.module
88 lines (80 loc) · 2.19 KB
/
hosting_environment.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* @file
* The hosting integration for the Environment module.
*/
/**
* Implements hook_form_alter().
*/
function hosting_environment_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'site_node_form') {
$form['environment'] = array(
'#type' => 'fieldset',
'#title' => t('Environment settings'),
'#description' => t('Specify the environment that this site should run under.'),
);
$form['environment']['environment'] = array(
'#type' => 'textfield',
'#title' => t('Environment'),
'#default_value' => isset($form['#node']->environment) ? $form['#node']->environment : '',
'#weight' => 0,
);
return $form;
}
}
/**
* Implements hook_node_insert().
*/
function hosting_environment_node_insert($node) {
if ($node->type == 'site' && !empty($node->environment)) {
$id = db_insert('hosting_environment')->fields(array(
'vid' => $node->vid,
'nid' => $node->nid,
'environment' => $node->environment,
))
->execute();
}
}
/**
* Implements hook_node_update().
*/
function hosting_environment_node_update($node) {
if (FALSE === db_query("SELECT environment FROM {hosting_environment} WHERE vid = :vid", array(':vid' => $node->vid))->fetchField()) {
hosting_environment_node_insert($node);
}
else {
db_update('hosting_environment')
->fields(array(
'environment' => $node->environment,
))
->condition('vid', $node->vid)
->execute();
}
}
/**
* Implements hook_node_load().
*/
function hosting_environment_node_load($nodes, $types) {
foreach ($nodes as $nid => &$node) {
if ($node->type == 'site') {
// array instead
$nodes[$nid]->environment = db_query("SELECT environment FROM {hosting_environment} WHERE vid = :vid", array(':vid' => $node->vid))->fetchField();;
}
}
}
/**
* Implements hook_node_delete().
*/
function hosting_environment_node_delete($node) {
db_delete('hosting_environment')
->condition('nid', $node->nid)
->execute();
}
/**
* Implements hook_revision_revision().
*/
function hosting_environment_node_revision_delete($node) {
db_delete('hosting_environment')
->condition('vid', $node->vid)
->execute();
}