-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextra_fields.module
More file actions
121 lines (111 loc) · 3.06 KB
/
extra_fields.module
File metadata and controls
121 lines (111 loc) · 3.06 KB
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
<?php
/**
* Implements hook_field_extra_fields().
*/
function extra_fields_field_extra_fields() {
$extra = array();
foreach (node_type_get_types() as $type) {
$extra['node'][$type->type] = array(
'display' => array(
'created' => array(
'label' => t('Post Date'),
'weight' => -5,
'type' => 'hidden',
),
'author' => array(
'label' => t('Author'),
'weight' => -3,
'type' => 'hidden',
),
),
);
if ($type->has_title) {
$extra['node'][$type->type]['display']['title'] = array(
'label' => t('Extra field: !title', array('!title' => $type->title_label)),
'weight' => -4,
'type' => 'hidden',
);
}
}
return $extra;
}
/**
* Implements hook_node_view().
*/
function extra_fields_node_view($node, $view_mode, $langcode) {
$node->content['created'] = array(
'#theme' => 'extra_fields_created',
'#node' => $node,
'#view_mode' => $view_mode
);
// only return this in a non-full page situation
if (!in_array($view_mode, array('default', 'full'))) {
$node->content['title'] = array(
'#theme' => 'extra_fields_title',
'#node' => $node,
'#view_mode' => $view_mode,
);
}
$node->content['author'] = array(
'#theme' => 'extra_fields_author',
'#node' => $node,
'#view_mode' => $view_mode,
);
}
/**
* Implements hook_theme().
*/
function extra_fields_theme($existing, $type, $theme, $path) {
return array(
'extra_fields_created' => array(
'variables' => array('node' => NULL, 'view_mode' => NULL),
),
'extra_fields_title' => array(
'variables' => array('node' => NULL, 'view_mode' => NULL),
),
'extra_fields_author' => array(
'variables' => array('node' => NULL, 'view_mode' => NULL),
),
);
}
function theme_extra_fields_created($variables) {
$node = $variables['node'];
$view_mode = $variables['view_mode'];
$output = '<div class="node-created">';
$output .= date('F j, Y', $node->created);
$output .= '</div>';
return $output;
}
function theme_extra_fields_title($variables) {
$node = $variables['node'];
$view_mode = $variables['view_mode'];
$entity_uri = entity_uri('node', $node);
$output = '<h3 class="node-title">';
$output .= l($node->title, $entity_uri['path']);
$output .= '</h3>';
return $output;
}
function theme_extra_fields_author($variables) {
$node = $variables['node'];
$view_mode = $variables['view_mode'];
$user = user_load($node->uid);
$output = '<div class="node-author">';
$output .= $user->name;
$output .= '</div>';
return $output;
}
/* Features implementation for exporting extra fields information */
/**
* Implements hook_features_api.
*/
function extra_fields_features_api() {
return array(
'extra_fields' => array(
'name' => t('Extra fields'),
'default_hook' => 'extra_fields_info',
'default_file' => FEATURES_DEFAULTS_INCLUDED,
'features_source' => TRUE,
'file' => drupal_get_path('module', 'extra_fields') .'/extra_fields.features.inc',
),
);
}