2 // $Id: content.panels.inc,v 1.1.2.6 2008/11/03 14:12:41 yched Exp $
6 * Panels 2 interface for CCK fieldgroups and fields.
10 * - Adjust the fields and groups that are displayed for context, when that
11 * capability is added to Panels.
16 * Implementation of hook_panels_content_types()
18 function content_panels_content_types() {
20 $items['content_field'] = array(
21 'title' => t('Content field'),
23 'content_types' => 'content_panels_field_content_types',
24 'add callback' => 'content_panels_edit_field',
25 'edit callback' => 'content_panels_edit_field',
26 'render callback' => 'content_panels_render_field',
27 'title callback' => 'content_panels_title_content',
32 function content_panels_field_content_types() {
34 'description' => array(
35 'title' => t('Content field'),
36 'icon' => 'icon_node.png',
37 'path' => panels_get_path('content_types/node'),
38 'description' => t('A content field from the referenced node.'),
39 'required context' => new panels_required_context(t('Node'), 'node'),
40 'category' => array(t('Node context'), -9),
45 function content_panels_edit_field($id, $parents, $conf = array()) {
47 $form['label'] = array(
49 '#title' => t('Label'),
50 '#default_value' => isset($conf['label']) ? $conf['label'] : '',
52 'normal' => t('Block title'),
53 'above' => t('Above'),
54 'inline' => t('Inline'),
55 'hidden' => t('Hidden'),
57 '#description' => t('Configure how the label is going to be displayed.'),
59 $options = array('' => '');
60 $fields = content_fields();
61 $field_types = _content_field_types();
62 foreach ($fields as $field_name => $field) {
63 $type_info = $field_types[$field['type']];
64 foreach ($type_info['formatters'] as $formatter_name => $formatter) {
65 $label = $type_info['label'] .':'. $field['widget']['label'] ;
66 $label .= $field['widget']['label'] != $field_name ? ' ('. $field_name .')' : '';
67 $options[$label][$field_name .':'. $formatter_name] = $formatter['label'];
71 $form['field_formatter'] = array(
73 '#title' => t('Field / Formatter'),
74 '#default_value' => isset($conf['field_formatter']) ? $conf['field_formatter'] : '',
75 '#options' => $options,
76 '#description' => t('Select a field and formatter.'),
83 * 'Title' callback for the 'field' content type.
85 function content_panels_title_content($subtype, $conf, $context) {
86 $data = explode(':', $conf['field_formatter']);
87 $field_name = $data[0];
88 $formatter = $data[1];
89 $fields = content_fields();
90 $field = $fields[$field_name];
91 $field_types = _content_field_types();
92 return t('"@s" field @name', array('@s' => $context->identifier, '@name' => $field_types[$field['type']]['label'] .': '. $field['widget']['label'] .' ('. $field['field_name'])) .')';
95 function content_panels_render_field($subtype, $conf, $panel_args, $context) {
96 if (is_array($context)) {
97 $context = array_pop($context);
99 $node = isset($context->data) ? drupal_clone($context->data) : NULL;
100 $data = explode(':', $conf['field_formatter']);
101 $field_name = $data[0];
102 $formatter = $data[1];
104 $field = content_fields($field_name);
106 // Force panel settings into the field's display settings.
107 $field['display_settings']['label']['format'] = $conf['label'] == 'normal' ? 'hidden' : $conf['label'];
108 $field['display_settings']['full']['format'] = $formatter;
109 $node->build_mode = NODE_BUILD_NORMAL;
110 // TODO : allow panel-specific template suggestions for content-field.tpl.php ?
112 $output = content_view_field($field, $node);
114 $block->module = 'content';
115 $block->delta = $field_name;
116 if ($conf['label'] == 'normal') {
117 $block->title = $field['widget']['label'];
119 $block->content = $output;