Projet

Général

Profil

Paste
Télécharger (6,58 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / content_types / node_context / node_content.inc @ 7e72b748

1
<?php
2

    
3
/**
4
 * Plugins are described by creating a $plugin array which will be used
5
 * by the system that includes this file.
6
 */
7
$plugin = array(
8
  'single' => TRUE,
9
  'title' => t('Node content'),
10
  'icon' => 'icon_node.png',
11
  'description' => t('The content of the referenced node.'),
12
  'required context' => new ctools_context_required(t('Node'), 'node'),
13
  'category' => t('Node'),
14
  'defaults' => array(
15
    'links' => TRUE,
16
    'no_extras' => TRUE,
17
    'override_title' => FALSE,
18
    'override_title_text' => '',
19
    'identifier' => '',
20
    'link' => TRUE,
21
    'leave_node_title' => FALSE,
22
    'build_mode' => 'teaser',
23
  ),
24
);
25

    
26
/**
27
 * Render the node content.
28
 */
29
function ctools_node_content_content_type_render($subtype, $conf, $panel_args, $context) {
30
  if (!empty($context) && ( empty($context->data) || empty($context->data->nid)) ){
31
    return;
32
  }
33

    
34
  $node = isset($context->data) ? clone $context->data : NULL;
35
  $block = new stdClass();
36
  $block->module = 'node';
37
  $block->delta  = $node->nid;
38

    
39
  if (empty($node)) {
40
    $block->delta   = 'placeholder';
41
    $block->title = t('Node title.');
42
    $block->content = t('Node content goes here.');
43
  }
44
  else {
45
    if (!empty($conf['identifier'])) {
46
      $node->ctools_template_identifier = $conf['identifier'];
47
    }
48

    
49
    $block->title = $node->title;
50
    if (empty($conf['leave_node_title'])) {
51
      $node->title = NULL;
52
    }
53
    $block->content = ctools_node_content_render_node($node, $conf);
54
  }
55

    
56
  if (!empty($conf['link']) && $node) {
57
    $block->title_link = "node/$node->nid";
58
  }
59

    
60
  return $block;
61
}
62

    
63
function ctools_node_content_render_node($node, $conf) {
64
  if (empty($node->content)) {
65
    // Copied from node_build_content() so we can fiddle with it as we render.
66
    $node->content = array();
67

    
68
    // The 'view' hook can be implemented to overwrite the default function
69
    // to display nodes.
70
    if (node_hook($node, 'view')) {
71
      $node = node_invoke($node, 'view', $conf['build_mode']);
72
    }
73

    
74
    // Build fields content.
75
    // In case of a multiple view, node_view_multiple() already ran the
76
    // 'prepare_view' step. An internal flag prevents the operation from running
77
    // twice.
78
    field_attach_prepare_view('node', array($node->nid => $node), $conf['build_mode']);
79
    entity_prepare_view('node', array($node->nid => $node));
80
    $node->content += field_attach_view('node', $node, $conf['build_mode']);
81

    
82
    // Always display a read more link on teasers because we have no way
83
    // to know when a teaser view is different than a full view.
84
    $links = array();
85
    if ($conf['build_mode'] == 'teaser') {
86
      $links['node-readmore'] = array(
87
        'title' => t('Read more'),
88
        'href' => 'node/' . $node->nid,
89
        'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title))
90
      );
91
    }
92

    
93
    $node->content['links'] = array(
94
      '#theme' => 'links__node',
95
      '#links' => $links,
96
      '#attributes' => array('class' => array('links', 'inline')),
97
    );
98

    
99
    if (empty($conf['no_extras'])) {
100
      // Allow modules to make their own additions to the node.
101
      $langcode = $GLOBALS['language_content']->language;
102
      module_invoke_all('node_view', $node, $conf['build_mode'], $langcode);
103
      module_invoke_all('entity_view', $node, 'node', $conf['build_mode'], $langcode);
104
    }
105
  }
106

    
107
  // Set the proper node part, then unset unused $node part so that a bad
108
  // theme can not open a security hole.
109
  $content = $node->content;
110

    
111
  $content += array(
112
    '#theme' => 'node',
113
    '#node' => $node,
114
    '#view_mode' => $conf['build_mode'],
115
    '#language' => NULL,
116
  );
117

    
118
  // Add contextual links for this node, except when the node is already being
119
  // displayed on its own page. Modules may alter this behavior (for example,
120
  // to restrict contextual links to certain view modes) by implementing
121
  // hook_node_view_alter().
122
  if (!empty($node->nid) && !($conf['build_mode'] == 'full' && node_is_page($node))) {
123
    $content['#contextual_links']['node'] = array('node', array($node->nid));
124
  }
125

    
126
  // Allow modules to modify the structured node.
127
  $type = 'node';
128
  drupal_alter(array('node_view', 'entity_view'), $content, $type);
129

    
130
  // Kill the links if not requested.
131
  if (!$conf['links']) {
132
    $content['links']['#access'] = FALSE;
133
  }
134

    
135
  return $content;
136
}
137

    
138
/**
139
 * Returns an edit form for the custom type.
140
 */
141
function ctools_node_content_content_type_edit_form($form, &$form_state) {
142
  $conf = $form_state['conf'];
143

    
144
  $form['leave_node_title'] = array(
145
    '#type' => 'checkbox',
146
    '#default_value' => !empty($conf['leave_node_title']),
147
    '#title' => t('Leave node title'),
148
    '#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.'),
149
  );
150

    
151
  $form['link'] = array(
152
    '#title' => t('Link title to node'),
153
    '#type' => 'checkbox',
154
    '#default_value' => $conf['link'],
155
    '#description' => t('Check here to make the title link to the node.'),
156
  );
157
  $form['links'] = array(
158
    '#type' => 'checkbox',
159
    '#default_value' => $conf['links'],
160
    '#title' => t('Include node links for "add comment", "read more" etc.'),
161
  );
162

    
163
  $form['no_extras'] = array(
164
    '#type' => 'checkbox',
165
    '#default_value' => $conf['no_extras'],
166
    '#title' => t('No extras'),
167
    '#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.'),
168
  );
169

    
170
  $form['identifier'] = array(
171
    '#type' => 'textfield',
172
    '#default_value' => $conf['identifier'],
173
    '#title' => t('Template identifier'),
174
    '#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.'),
175
  );
176

    
177
  $entity = entity_get_info('node');
178
  $build_mode_options = array();
179
  foreach ($entity['view modes'] as $mode => $option) {
180
    $build_mode_options[$mode] = $option['label'];
181
  }
182

    
183
  $form['build_mode'] = array(
184
    '#title' => t('Build mode'),
185
    '#type' => 'select',
186
    '#description' => t('Select a build mode for this node.'),
187
    '#options' => $build_mode_options,
188
    '#default_value' => $conf['build_mode'],
189
  );
190

    
191
  return $form;
192
}
193

    
194
function ctools_node_content_content_type_edit_form_submit($form, &$form_state) {
195
  // Copy everything from our defaults.
196
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
197
    $form_state['conf'][$key] = $form_state['values'][$key];
198
  }
199
}
200

    
201
function ctools_node_content_content_type_admin_title($subtype, $conf, $context) {
202
  return t('"@s" content', array('@s' => $context->identifier));
203
}
204