diff --git a/sites/all/modules/cck/content_panels.inc b/sites/all/modules/cck/content_panels.inc index 7059cc1..a9e0cd8 100644 --- a/sites/all/modules/cck/content_panels.inc +++ b/sites/all/modules/cck/content_panels.inc @@ -1,11 +1,23 @@ t('CCK fields'), + 'weight' => -10, + 'single' => FALSE, + 'content_types' => 'content_admin_content_types_cck_content', + 'add callback' => 'content_admin_edit_cck_content', + 'edit callback' => 'content_admin_edit_cck_content', + 'render callback' => 'content_admin_render_cck_content', + ); if (module_exists('fieldgroup')) { $items['node_cck_group'] = array( 'title' => t('Node CCK Group'), @@ -20,6 +32,100 @@ function content_panels_content_types() { return $items; } +function content_admin_content_types_cck_content() { + $fields = content_fields(); + $items = array(); + + foreach ($fields as $field_name => $field) { + $items[$field_name] = array( + 'title' => $field['widget']['label'], + 'icon' => 'icon_node.png', + 'path' => panels_get_path('content_types/node'), + 'required context' => new panels_required_context(t('Node'), 'node'), + 'category' => array(t('Content fields'), -9), + ); + } + + return $items; +} + +function content_admin_edit_cck_content($id, $parents, $conf = array()) { + $form = array(); + $info = _content_type_info($id); + $field = $info['fields'][$id]; + $field_info = $info['field types'][$field['type']]; + + $form['field_name'] = array( + '#type' => 'value', + '#value' => $id, + ); + $form['title_formatter'] = array( + '#type' => 'select', + '#title' => t('Title formatter'), + '#default_value' => $conf['title_formatter'], + '#options' => array( + 'normal' => t('Block title'), + 'above' => t('Above'), + 'inline' => t('Inline'), + 'hidden' => t('hidden'), + ), + '#description' => t('Configure how the title is going to be displayed'), + ); + + $options = array(); + foreach ($field_info['formatters'] as $type => $formatter) { + $options[$type] = $formatter['label']; + } + + $form['formatter'] = array( + '#type' => 'select', + '#title' => t('Formatter'), + '#default_value' => $conf['formatter'], + '#options' => $options, + '#description' => t('Select how the field is going to be displayed'), + ); + return $form; +} + +function content_admin_render_cck_content($conf, $panel_args, $context) { + if (!empty($context) && empty($context->data)) { + return; + } + + $node = isset($context->data) ? drupal_clone($context->data) : NULL; + $info = _content_type_info($id); + $field = $info['fields'][$conf['field_name']]; + $field_info = $info['field types'][$field['type']]; + + $field['display_settings']['label']['format'] = $conf['title_formatter'] == 'normal' ? 'hidden' : $conf['title_formatter']; + $field['display_settings']['full']['format'] = $conf['formatter']; + + $block->module = 'content'; + $block->delta = $conf['field_name']; + + if ($conf['title_formatter'] == 'normal') { + $block->title = $field['widget']['label']; + } + $node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); + + if (content_handle('field', 'view', $field) == CONTENT_CALLBACK_CUSTOM) { + $module = $field_types[$field['type']]['module']; + $function = $field['type'] .'_field'; + if (function_exists($function)) { + $value = $function('view', $node, $field, $node_field, 0, 0); + } + } + else { + foreach ($node_field as $delta => $item) { + $node_field[$delta]['view'] = content_format($field, $item, $conf['formatter'], $node); + } + $value = theme('field', $node, $field, $node_field, 0, 0); + } + $block->content = $value; + + return $block; +} + /** * 'Render' callback for the 'CCK group' content type. */ @@ -233,3 +339,4 @@ function content_user_from_userref_context_settings_form($conf) { return $form; } +