Projet

Général

Profil

Paste
Télécharger (2,97 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / content_types / node_context / node_links.inc @ c304a780

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 links'),
12
  'icon' => 'icon_node.png',
13
  'description' => t('Node links of the referenced node.'),
14
  'required context' => new ctools_context_required(t('Node'), 'node'),
15
  'category' => t('Node'),
16
  'defaults' => array(
17
    'override_title' => FALSE,
18
    'override_title_text' => '',
19
    'build_mode' => '',
20
    'identifier' => '',
21
    'link' => TRUE,
22
  ),
23
);
24

    
25
/**
26
 * Output function for the 'node' content type. Outputs a node
27
 * based on the module and delta supplied in the configuration.
28
 */
29
function ctools_node_links_content_type_render($subtype, $conf, $panel_args, $context) {
30
  if (!empty($context) && empty($context->data)) {
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->subject = t('Node title.');
42
    $block->content = t('Node links go here.');
43
  }
44
  else {
45
    if (!empty($conf['identifier'])) {
46
      $node->panel_identifier = $conf['identifier'];
47
    }
48

    
49
    $block->subject = $node->title;
50
    node_build_content($node, $conf['build_mode']);
51
    $block->content = $node->content['links'];
52
  }
53

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

    
60
/**
61
 * Returns an edit form for the custom type.
62
 */
63
function ctools_node_links_content_type_edit_form($form, &$form_state) {
64
  $conf = $form_state['conf'];
65

    
66
  $form['link'] = array(
67
    '#title' => t('Link title to node'),
68
    '#type' => 'checkbox',
69
    '#default_value' => $conf['link'],
70
    '#description' => t('Check here to make the title link to the node.'),
71
  );
72

    
73
  $entity = entity_get_info('node');
74
  $build_mode_options = array();
75
  foreach ($entity['view modes'] as $mode => $option) {
76
    $build_mode_options[$mode] = $option['label'];
77
  }
78

    
79
  $form['build_mode'] = array(
80
    '#title' => t('Build mode'),
81
    '#type' => 'select',
82
    '#description' => t('Select a build mode for this node.'),
83
    '#options' => $build_mode_options,
84
    '#default_value' => $conf['build_mode'],
85
  );
86

    
87
  $form['identifier'] = array(
88
    '#type' => 'textfield',
89
    '#default_value' => $conf['identifier'],
90
    '#title' => t('Identifier'),
91
    '#description' => t('Whatever is placed here will appear in @identifier, to help theme node links displayed on the panel', array('@identifier' => $node->panel_identifier)),
92
  );
93

    
94
  return $form;
95
}
96

    
97
function ctools_node_links_content_type_edit_form_submit($form, &$form_state) {
98
  // Copy everything from our defaults.
99
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
100
    $form_state['conf'][$key] = $form_state['values'][$key];
101
  }
102
}
103

    
104
function ctools_node_links_content_type_admin_title($subtype, $conf, $context) {
105
  return t('"@s" links', array('@s' => $context->identifier));
106
}