Commit | Line | Data |
---|---|---|
7f254ad8 AE |
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 links'), | |
10 | 'icon' => 'icon_node.png', | |
11 | 'description' => t('Node links of the referenced node.'), | |
12 | 'required context' => new ctools_context_required(t('Node'), 'node'), | |
13 | 'category' => t('Node'), | |
14 | 'defaults' => array( | |
15 | 'override_title' => FALSE, | |
16 | 'override_title_text' => '', | |
17 | 'build_mode' => '', | |
18 | 'identifier' => '', | |
19 | 'link' => TRUE, | |
20 | ), | |
21 | ); | |
22 | ||
23 | /** | |
24 | * Output function for the 'node' content type. Outputs a node | |
25 | * based on the module and delta supplied in the configuration. | |
26 | */ | |
27 | function ctools_node_links_content_type_render($subtype, $conf, $panel_args, $context) { | |
28 | if (!empty($context) && empty($context->data)) { | |
29 | return; | |
30 | } | |
31 | ||
32 | $node = isset($context->data) ? clone($context->data) : NULL; | |
33 | $block = new stdClass(); | |
34 | $block->module = 'node'; | |
35 | $block->delta = $node->nid; | |
36 | ||
37 | if (empty($node)) { | |
38 | $block->delta = 'placeholder'; | |
39 | $block->subject = t('Node title.'); | |
40 | $block->content = t('Node links go here.'); | |
41 | } | |
42 | else { | |
43 | if (!empty($conf['identifier'])) { | |
44 | $node->panel_identifier = $conf['identifier']; | |
45 | } | |
46 | ||
47 | $block->subject = $node->title; | |
48 | node_build_content($node, $conf['build_mode']); | |
49 | $block->content = $node->content['links']; | |
50 | } | |
51 | ||
52 | if (!empty($conf['link']) && $node) { | |
53 | $block->title_link = "node/$node->nid"; | |
54 | } | |
55 | return $block; | |
56 | } | |
57 | ||
58 | /** | |
59 | * Returns an edit form for the custom type. | |
60 | */ | |
61 | function ctools_node_links_content_type_edit_form($form, &$form_state) { | |
62 | $conf = $form_state['conf']; | |
63 | ||
64 | $form['link'] = array( | |
65 | '#title' => t('Link title to node'), | |
66 | '#type' => 'checkbox', | |
67 | '#default_value' => $conf['link'], | |
68 | '#description' => t('Check here to make the title link to the node.'), | |
69 | ); | |
70 | ||
71 | $entity = entity_get_info('node'); | |
72 | $build_mode_options = array(); | |
73 | foreach ($entity['view modes'] as $mode => $option) { | |
74 | $build_mode_options[$mode] = $option['label']; | |
75 | } | |
76 | ||
77 | $form['build_mode'] = array( | |
78 | '#title' => t('Build mode'), | |
79 | '#type' => 'select', | |
80 | '#description' => t('Select a build mode for this node.'), | |
81 | '#options' => $build_mode_options, | |
82 | '#default_value' => $conf['build_mode'], | |
83 | ); | |
84 | ||
85 | $form['identifier'] = array( | |
86 | '#type' => 'textfield', | |
87 | '#default_value' => $conf['identifier'], | |
88 | '#title' => t('Identifier'), | |
89 | '#description' => t('Whatever is placed here will appear in @identifier, to help theme node links displayed on the panel', array('@identifier' => $node->panel_identifier)), | |
90 | ); | |
91 | ||
92 | return $form; | |
93 | } | |
94 | ||
95 | function ctools_node_links_content_type_edit_form_submit($form, &$form_state) { | |
96 | // Copy everything from our defaults. | |
97 | foreach (array_keys($form_state['plugin']['defaults']) as $key) { | |
98 | $form_state['conf'][$key] = $form_state['values'][$key]; | |
99 | } | |
100 | } | |
101 | ||
102 | function ctools_node_links_content_type_admin_title($subtype, $conf, $context) { | |
103 | return t('"@s" links', array('@s' => $context->identifier)); | |
104 | } | |
105 |