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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 | <?php
function node_example_menu() {
$items['examples/node_example'] = array(
'page callback' => 'node_example_page',
'access arguments' => array('access content'),
'title' => 'Node Example',
);
return $items;
}
function node_example_page() {
$renderable_array = array();
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type AND n.status = :status';
$result = db_query($sql,
array(
':type' => 'node_example',
':status' => 1,
)
);
$renderable_array['explanation'] = array(
'#markup' => t("Node Example nodes you've created will be displayed here. Note that the color fields will be displayed differently in this list, than if you view the node normally. Click on the node title to see the difference. This is a result of using our 'example_node_list' node view type."),
);
foreach ($result as $row) {
$node = node_load($row->nid);
$renderable_array['node_list'][]= node_view($node, 'example_node_list');
}
return $renderable_array;
}
function node_example_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['example_node_list'] = array(
'label' => t('Example Node List'),
'custom settings' => TRUE,
);
}
function node_example_field_formatter_info() {
return array(
'node_example_colors' => array(
'label' => t('Node Example Color Handle'),
'field types' => array('text'),
),
);
}
function node_example_field_formatter_view($object_type, $object, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case 'node_example_colors':
foreach ($items as $delta => $item) {
$element[$delta]['#type'] = 'markup';
$color = $item['safe_value'];
$element[$delta]['#markup'] = theme('example_node_color', array('color' => $color));
}
break;
}
return $element;
}
function node_example_theme($existing, $type, $theme, $path) {
return array(
'example_node_color' => array(
'variables' => array('color' => NULL),
),
);
}
function node_example_help($path, $arg) {
switch ($path) {
case 'examples/node_example':
return "<p>" . t("The Node Example module provides a custom node type.
You can create new Example Node nodes using the <a href='!nodeadd'>node add form</a>.",
array('!nodeadd' => url('node/add/node-example'))) . "</p>";
}
}
function theme_example_node_color($variables) {
$output = '<span style="background-color: #ccc; padding: 1em; margin-bottom: 1em; float: left; color: ' . $variables['color'] . '">' . $variables['color'] . '</span>';
return $output;
}
|