1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Plugins are described by creating a $plugin array which will be used
|
6
|
* by the system that includes this file.
|
7
|
*/
|
8
|
|
9
|
$plugin = array(
|
10
|
'single' => TRUE,
|
11
|
'title' => t('Node content'),
|
12
|
'icon' => 'icon_node.png',
|
13
|
'description' => t('The content of the referenced node.'),
|
14
|
'required context' => new ctools_context_required(t('Node'), 'node'),
|
15
|
'category' => t('Node'),
|
16
|
'defaults' => array(
|
17
|
'links' => TRUE,
|
18
|
'no_extras' => TRUE,
|
19
|
'override_title' => FALSE,
|
20
|
'override_title_text' => '',
|
21
|
'identifier' => '',
|
22
|
'link' => TRUE,
|
23
|
'leave_node_title' => FALSE,
|
24
|
'build_mode' => 'teaser',
|
25
|
),
|
26
|
);
|
27
|
|
28
|
/**
|
29
|
* Render the node content.
|
30
|
*/
|
31
|
function ctools_node_content_content_type_render($subtype, $conf, $panel_args, $context) {
|
32
|
if (!empty($context) && (empty($context->data) || empty($context->data->nid))) {
|
33
|
return;
|
34
|
}
|
35
|
|
36
|
$node = isset($context->data) ? clone $context->data : NULL;
|
37
|
$block = new stdClass();
|
38
|
$block->module = 'node';
|
39
|
$block->delta = $node->nid;
|
40
|
|
41
|
if (empty($node)) {
|
42
|
$block->delta = 'placeholder';
|
43
|
$block->title = t('Node title.');
|
44
|
$block->content = t('Node content goes here.');
|
45
|
}
|
46
|
else {
|
47
|
if (!empty($conf['identifier'])) {
|
48
|
$node->ctools_template_identifier = $conf['identifier'];
|
49
|
}
|
50
|
|
51
|
$block->title = $node->title;
|
52
|
if (empty($conf['leave_node_title'])) {
|
53
|
$node->title = NULL;
|
54
|
}
|
55
|
$block->content = ctools_node_content_render_node($node, $conf);
|
56
|
}
|
57
|
|
58
|
if (!empty($conf['link']) && $node) {
|
59
|
$block->title_link = "node/$node->nid";
|
60
|
}
|
61
|
|
62
|
return $block;
|
63
|
}
|
64
|
|
65
|
function ctools_node_content_render_node($node, $conf) {
|
66
|
if (empty($node->content)) {
|
67
|
// Copied from node_build_content() so we can fiddle with it as we render.
|
68
|
$node->content = array();
|
69
|
|
70
|
// The 'view' hook can be implemented to overwrite the default function
|
71
|
// to display nodes.
|
72
|
if (node_hook($node, 'view')) {
|
73
|
$node = node_invoke($node, 'view', $conf['build_mode']);
|
74
|
}
|
75
|
|
76
|
// Build fields content.
|
77
|
// In case of a multiple view, node_view_multiple() already ran the
|
78
|
// 'prepare_view' step. An internal flag prevents the operation from running
|
79
|
// twice.
|
80
|
field_attach_prepare_view('node', array($node->nid => $node), $conf['build_mode']);
|
81
|
entity_prepare_view('node', array($node->nid => $node));
|
82
|
$node->content += field_attach_view('node', $node, $conf['build_mode']);
|
83
|
|
84
|
// Always display a read more link on teasers because we have no way
|
85
|
// to know when a teaser view is different than a full view.
|
86
|
$links = array();
|
87
|
if ($conf['build_mode'] == 'teaser') {
|
88
|
$links['node-readmore'] = array(
|
89
|
'title' => t('Read more'),
|
90
|
'href' => 'node/' . $node->nid,
|
91
|
'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title)),
|
92
|
);
|
93
|
}
|
94
|
|
95
|
$node->content['links'] = array(
|
96
|
'#theme' => 'links__node',
|
97
|
'#links' => $links,
|
98
|
'#attributes' => array('class' => array('links', 'inline')),
|
99
|
);
|
100
|
|
101
|
if (empty($conf['no_extras'])) {
|
102
|
// Allow modules to make their own additions to the node.
|
103
|
$langcode = $GLOBALS['language_content']->language;
|
104
|
module_invoke_all('node_view', $node, $conf['build_mode'], $langcode);
|
105
|
module_invoke_all('entity_view', $node, 'node', $conf['build_mode'], $langcode);
|
106
|
}
|
107
|
}
|
108
|
|
109
|
// Set the proper node part, then unset unused $node part so that a bad
|
110
|
// theme can not open a security hole.
|
111
|
$content = $node->content;
|
112
|
|
113
|
$content += array(
|
114
|
'#theme' => 'node',
|
115
|
'#node' => $node,
|
116
|
'#view_mode' => $conf['build_mode'],
|
117
|
'#language' => NULL,
|
118
|
);
|
119
|
|
120
|
// Add contextual links for this node, except when the node is already being
|
121
|
// displayed on its own page. Modules may alter this behavior (for example,
|
122
|
// to restrict contextual links to certain view modes) by implementing
|
123
|
// hook_node_view_alter().
|
124
|
if (!empty($node->nid) && !($conf['build_mode'] == 'full' && node_is_page($node))) {
|
125
|
$content['#contextual_links']['node'] = array('node', array($node->nid));
|
126
|
}
|
127
|
|
128
|
// Allow modules to modify the structured node.
|
129
|
$type = 'node';
|
130
|
drupal_alter(array('node_view', 'entity_view'), $content, $type);
|
131
|
|
132
|
// Kill the links if not requested.
|
133
|
if (!$conf['links']) {
|
134
|
$content['links']['#access'] = FALSE;
|
135
|
}
|
136
|
|
137
|
return $content;
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* Returns an edit form for the custom type.
|
142
|
*/
|
143
|
function ctools_node_content_content_type_edit_form($form, &$form_state) {
|
144
|
$conf = $form_state['conf'];
|
145
|
|
146
|
$form['leave_node_title'] = array(
|
147
|
'#type' => 'checkbox',
|
148
|
'#default_value' => !empty($conf['leave_node_title']),
|
149
|
'#title' => t('Leave node title'),
|
150
|
'#description' => t('Advanced: if checked, do not touch the node title; this can cause the node title to appear twice unless your theme is aware of this.'),
|
151
|
);
|
152
|
|
153
|
$form['link'] = array(
|
154
|
'#title' => t('Link title to node'),
|
155
|
'#type' => 'checkbox',
|
156
|
'#default_value' => $conf['link'],
|
157
|
'#description' => t('Check here to make the title link to the node.'),
|
158
|
);
|
159
|
$form['links'] = array(
|
160
|
'#type' => 'checkbox',
|
161
|
'#default_value' => $conf['links'],
|
162
|
'#title' => t('Include node links for "add comment", "read more" etc.'),
|
163
|
);
|
164
|
|
165
|
$form['no_extras'] = array(
|
166
|
'#type' => 'checkbox',
|
167
|
'#default_value' => $conf['no_extras'],
|
168
|
'#title' => t('No extras'),
|
169
|
'#description' => t('Check here to disable additions that modules might make to the node, such as file attachments and CCK fields; this should just display the basic teaser or body.'),
|
170
|
);
|
171
|
|
172
|
$form['identifier'] = array(
|
173
|
'#type' => 'textfield',
|
174
|
'#default_value' => $conf['identifier'],
|
175
|
'#title' => t('Template identifier'),
|
176
|
'#description' => t('This identifier will be added as a template suggestion to display this node: node--panel--IDENTIFIER.tpl.php. Please see the Drupal theming guide for information about template suggestions.'),
|
177
|
);
|
178
|
|
179
|
$entity = entity_get_info('node');
|
180
|
$build_mode_options = array();
|
181
|
foreach ($entity['view modes'] as $mode => $option) {
|
182
|
$build_mode_options[$mode] = $option['label'];
|
183
|
}
|
184
|
|
185
|
$form['build_mode'] = array(
|
186
|
'#title' => t('Build mode'),
|
187
|
'#type' => 'select',
|
188
|
'#description' => t('Select a build mode for this node.'),
|
189
|
'#options' => $build_mode_options,
|
190
|
'#default_value' => $conf['build_mode'],
|
191
|
);
|
192
|
|
193
|
return $form;
|
194
|
}
|
195
|
|
196
|
function ctools_node_content_content_type_edit_form_submit($form, &$form_state) {
|
197
|
// Copy everything from our defaults.
|
198
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
199
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
200
|
}
|
201
|
}
|
202
|
|
203
|
function ctools_node_content_content_type_admin_title($subtype, $conf, $context) {
|
204
|
return t('"@s" content', array('@s' => $context->identifier));
|
205
|
}
|