0ca6e24b39228ad2a1c6710b3d614fa360740b09
6 * This file provides a CTools content type for fieldgroups.
10 * Callback function to supply a list of content types.
12 function fieldgroup_content_fieldgroup_ctools_content_types() {
14 'title' => t('Content fieldgroup'),
15 'defaults' => array('empty' => ''),
20 * Return all fieldgroup content types available.
22 function fieldgroup_content_fieldgroup_content_type_content_types() {
23 // This will hold all the individual fieldgroup content types.
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') {
35 // Name the content type a combination of fieldgroup and node type names.
36 $content_type_name = $fieldgroup['type_name'] .
':' .
$fieldgroup['group_name'];
38 // Assemble the information about the content type.
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']),
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']))),
49 $types[$content_type_name] = $info;
57 * Output function for the 'fieldgroup' content type.
59 function fieldgroup_content_fieldgroup_content_type_render($subtype, $conf, $panel_args, $context) {
60 if (!isset($context->data
)) {
63 $node = drupal_clone($context->data
);
65 // Extract the node type and fieldgroup name from the subtype.
66 list($node_type, $fieldgroup_name) = explode(':', $subtype, 2);
68 // Get a list of all fieldgroups for this node type.
69 $groups = fieldgroup_groups($node_type);
71 if (!isset($groups[$fieldgroup_name])) {
75 $group = $groups[$fieldgroup_name];
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;
86 $block = new
stdClass();
87 $block->title
= $group['label'];
88 $block->content
= !empty($output) ?
theme('fieldgroup_content_type', $output, $node->nid
) : $conf['empty'];
94 * Allows users to theme the fieldgroup content type.
96 function theme_fieldgroup_content_type($vars, $nid) {
97 return implode('', $vars);
101 * Returns a settings form for the custom type.
103 function fieldgroup_content_fieldgroup_content_type_edit_form(&$form, &$form_state) {
104 $conf = $form_state['conf'];
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.'),
111 '#default_value' => $conf['empty'],
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];
123 * Admin title for fieldgroup content type.
125 function fieldgroup_content_fieldgroup_content_type_admin_title($subtype, $conf, $context) {
126 return t('"@s" fieldgroup (@name)', array('@s' => $context->identifier
, '@name' => $subtype));