0ca6e24b39228ad2a1c6710b3d614fa360740b09
[project/cck.git] / modules / fieldgroup / panels / content_types / content_fieldgroup.inc
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * This file provides a CTools content type for fieldgroups.
7 */
8
9 /**
10 * Callback function to supply a list of content types.
11 */
12 function fieldgroup_content_fieldgroup_ctools_content_types() {
13 return array(
14 'title' => t('Content fieldgroup'),
15 'defaults' => array('empty' => ''),
16 );
17 }
18
19 /**
20 * Return all fieldgroup content types available.
21 */
22 function fieldgroup_content_fieldgroup_content_type_content_types() {
23 // This will hold all the individual fieldgroup content types.
24 $types = array();
25
26 // The outer loop goes through each node type with groups.
27 foreach (fieldgroup_groups() as $node_type_groups) {
28 // The inner loop gives us each fieldgroup on each node type with groups.
29 foreach ($node_type_groups as $fieldgroup) {
30 // Skip field groups that are not of standard type.
31 if ($fieldgroup['group_type'] != 'standard') {
32 continue;
33 }
34
35 // Name the content type a combination of fieldgroup and node type names.
36 $content_type_name = $fieldgroup['type_name'] . ':' . $fieldgroup['group_name'];
37
38 // Assemble the information about the content type.
39 $info = array(
40 'category' => t('Content'),
41 'title' => t('@group in @type (standard field group)', array(
42 '@group' => t($fieldgroup['label']),
43 '@type' => node_get_types('name', $fieldgroup['type_name']),
44 )),
45 'description' => t('All fields from this field group on the referenced node.'),
46 'required context' => new ctools_context_required(t('Node'), 'node', array('type' => array($fieldgroup['type_name']))),
47 );
48
49 $types[$content_type_name] = $info;
50 }
51 }
52
53 return $types;
54 }
55
56 /**
57 * Output function for the 'fieldgroup' content type.
58 */
59 function fieldgroup_content_fieldgroup_content_type_render($subtype, $conf, $panel_args, $context) {
60 if (!isset($context->data)) {
61 return;
62 }
63 $node = drupal_clone($context->data);
64
65 // Extract the node type and fieldgroup name from the subtype.
66 list($node_type, $fieldgroup_name) = explode(':', $subtype, 2);
67
68 // Get a list of all fieldgroups for this node type.
69 $groups = fieldgroup_groups($node_type);
70
71 if (!isset($groups[$fieldgroup_name])) {
72 return;
73 }
74
75 $group = $groups[$fieldgroup_name];
76 $output = array();
77
78 foreach ($group['fields'] as $field_name => $field) {
79 $field = content_fields($field_name, $node_type);
80 $field_view = content_view_field($field, $node);
81 if (!is_null($field_view)) {
82 $output[] = $field_view;
83 }
84 }
85
86 $block = new stdClass();
87 $block->title = $group['label'];
88 $block->content = !empty($output) ? theme('fieldgroup_content_type', $output, $node->nid) : $conf['empty'];
89
90 return $block;
91 }
92
93 /**
94 * Allows users to theme the fieldgroup content type.
95 */
96 function theme_fieldgroup_content_type($vars, $nid) {
97 return implode('', $vars);
98 }
99
100 /**
101 * Returns a settings form for the custom type.
102 */
103 function fieldgroup_content_fieldgroup_content_type_edit_form(&$form, &$form_state) {
104 $conf = $form_state['conf'];
105
106 $form['empty'] = array(
107 '#type' => 'textarea',
108 '#title' => 'Empty text',
109 '#description' => t('Text to display if group has no data. Note that title will not display unless overridden.'),
110 '#rows' => 5,
111 '#default_value' => $conf['empty'],
112 );
113 }
114
115 function fieldgroup_content_fieldgroup_content_type_edit_form_submit(&$form, &$form_state) {
116 // Copy everything from our defaults.
117 foreach (array_keys($form_state['plugin']['defaults']) as $key) {
118 $form_state['conf'][$key] = $form_state['values'][$key];
119 }
120 }
121
122 /**
123 * Admin title for fieldgroup content type.
124 */
125 function fieldgroup_content_fieldgroup_content_type_admin_title($subtype, $conf, $context) {
126 return t('"@s" fieldgroup (@name)', array('@s' => $context->identifier, '@name' => $subtype));
127 }