Index: includes/panels/content_types/content_field.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/includes/panels/content_types/Attic/content_field.inc,v retrieving revision 1.1.2.6 diff -u -p -r1.1.2.6 content_field.inc --- includes/panels/content_types/content_field.inc 8 Jul 2009 23:23:30 -0000 1.1.2.6 +++ includes/panels/content_types/content_field.inc 10 Jul 2009 19:33:46 -0000 @@ -31,7 +31,7 @@ function content_content_field_content_t if (!isset($types[$field_name])) { $types[$field_name] = array( 'category' => t('Content'), - 'title' => t('@widget_label (@field_name) - @field_type', array( + 'title' => t('field: @widget_label (@field_name) - @field_type', array( '@widget_label' => t($field['widget']['label']), '@field_name' => $field_name, '@field_type' => t($field_types[$field['type']]['label']), @@ -85,7 +85,7 @@ function content_content_field_content_t } // Force panel settings into the field's display settings. - $field['display_settings']['label']['format'] = $conf['label'] == 'normal' ? 'hidden' : $conf['label']; + $field['display_settings']['label']['format'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label']; $field['display_settings']['full']['format'] = $formatter; $node->build_mode = NODE_BUILD_NORMAL; // TODO : allow panel-specific template suggestions for content-field.tpl.php ? @@ -96,7 +96,7 @@ function content_content_field_content_t $block->module = 'content'; $block->delta = $field_name; if ($conf['label'] == 'normal') { - $block->title = $field['widget']['label']; + $block->title = t($field['widget']['label']); } $block->content = $output; @@ -111,15 +111,14 @@ function content_content_field_content_t $form['label'] = array( '#type' => 'select', - '#title' => t('Label'), + '#title' => t('Field label'), '#default_value' => isset($conf['label']) ? $conf['label'] : '', '#options' => array( 'normal' => t('Block title'), 'above' => t('Above'), 'inline' => t('Inline'), - 'hidden' => t('Hidden'), ), - '#description' => t('Configure how the label is going to be displayed.'), + '#description' => t('Configure how the label is going to be displayed. This option takes no effect when "Override title" option is enabled, the specified block title is displayed instead.'), ); // Extract the field name from the panels content type subtype. @@ -142,7 +141,7 @@ function content_content_field_content_t $form['formatter'] = array( '#type' => 'select', - '#title' => t('Formatter'), + '#title' => t('Field formatter'), '#default_value' => isset($conf['formatter']) ? $conf['formatter'] : 'default', '#options' => $options, '#description' => t('Select a formatter.'), @@ -161,5 +160,16 @@ function content_content_field_content_t * Admin title for field content type. */ function content_content_field_content_type_admin_title($subtype, $conf, $context) { - return t('"@s" field (@name)', array('@s' => $context->identifier, '@name' => $subtype)); + // Get all fields on the site. + $field_types = _content_field_types(); + + // Get all the information about our field. + $field = content_fields($subtype); + + return t('"@s" field: @widget_label (@field_name) - @field_type', array( + '@s' => $context->identifier, + '@widget_label' => t($field['widget']['label']), + '@field_name' => $subtype, + '@field_type' => t($field_types[$field['type']]['label']), + )); } Index: modules/fieldgroup/fieldgroup.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/modules/fieldgroup/fieldgroup.module,v retrieving revision 1.79.2.48 diff -u -p -r1.79.2.48 fieldgroup.module --- modules/fieldgroup/fieldgroup.module 29 Apr 2009 20:51:52 -0000 1.79.2.48 +++ modules/fieldgroup/fieldgroup.module 10 Jul 2009 19:39:52 -0000 @@ -524,83 +524,179 @@ function fieldgroup_nodeapi(&$node, $op, case 'view': // Prevent against invalid 'nodes' built by broken 3rd party code. if (isset($node->type)) { - // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. - if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { - $context = $teaser ? 'teaser' : 'full'; - } - else { - $context = $node->build_mode; + // Build the node content element needed to render each fieldgroup. + foreach (fieldgroup_groups($node->type) as $group) { + fieldgroup_build_content($group, $node, $teaser, $page); } + } + break; + } +} - foreach (fieldgroup_groups($node->type) as $group_name => $group) { - // Do not include group labels when indexing content. - if ($context == NODE_BUILD_SEARCH_INDEX) { - $group['settings']['display']['label'] = 'hidden'; - } - $label = $group['settings']['display']['label'] == 'above'; - $element = array( - '#title' => $label ? check_plain(t($group['label'])) : '', - '#description' => $label ? content_filter_xss(t($group['settings']['display']['description'])) : '', - ); - $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset'; - - switch ($format) { - case 'simple': - $element['#type'] = 'fieldgroup_simple'; - $element['#group_name'] = $group_name; - $element['#node'] = $node; - break; - case 'hidden': - $element['#access'] = FALSE; - break; - - case 'fieldset_collapsed': - $element['#collapsed'] = TRUE; - case 'fieldset_collapsible': - $element['#collapsible'] = TRUE; - case 'fieldset': - $element['#type'] = 'fieldgroup_fieldset'; - $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); - break; - } - foreach ($group['fields'] as $field_name => $field) { - if (isset($node->content[$field_name])) { - $element[$field_name] = $node->content[$field_name]; - } - } - - // Allow other modules to alter the group view. - // Can't use module_invoke_all because we want - // to be able to use a reference to $node and $element. - foreach (module_implements('fieldgroup_view') as $module) { - $function = $module .'_fieldgroup_view'; - $function($node, $element, $group, $context); - } - - foreach ($group['fields'] as $field_name => $field) { - if (isset($node->content[$field_name])) { - unset($node->content[$field_name]); - } - } - - // The wrapper lets us get the themed output for the group - // to populate the $GROUP_NAME_rendered variable for node templates, - // and hide it from the $content variable if needed. - // See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper(). - $wrapper = array( - 'group' => $element, - '#weight' => $group['weight'], - '#post_render' => array('fieldgroup_wrapper_post_render'), - '#group_name' => $group_name, - '#type_name' => $node->type, - '#context' => $context, - ); +/** + * Build the node content element needed to render a fieldgroup. + * + * @param $group + * The field group definition. + * @param $node + * The node containing the field group to display. Can be a 'pseudo-node', + * containing at least 'type', 'nid', 'vid', and the content for fields + * required for the group. + * @param $teaser + * @param $page + * Similar to hook_nodeapi('view'). + * + * @see fieldgroup_nodeapi() + * @see fieldgroup_view_group() + */ +function fieldgroup_build_content($group, &$node, $teaser, $page) { + // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. + if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { + $context = $teaser ? 'teaser' : 'full'; + } + else { + $context = $node->build_mode; + } - $node->content[$group_name] = $wrapper; - } - } + $group_name = $group['group_name']; + + // Do not include group labels when indexing content. + if ($context == NODE_BUILD_SEARCH_INDEX) { + $group['settings']['display']['label'] = 'hidden'; + } + $label = $group['settings']['display']['label'] == 'above'; + $element = array( + '#title' => $label ? check_plain(t($group['label'])) : '', + '#description' => $label ? content_filter_xss(t($group['settings']['display']['description'])) : '', + ); + $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset'; + + switch ($format) { + case 'simple': + $element['#type'] = 'fieldgroup_simple'; + $element['#group_name'] = $group_name; + $element['#node'] = $node; break; + case 'hidden': + $element['#access'] = FALSE; + break; + case 'fieldset_collapsed': + $element['#collapsed'] = TRUE; + case 'fieldset_collapsible': + $element['#collapsible'] = TRUE; + case 'fieldset': + $element['#type'] = 'fieldgroup_fieldset'; + $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); + break; + } + foreach ($group['fields'] as $field_name => $field) { + if (isset($node->content[$field_name])) { + $element[$field_name] = $node->content[$field_name]; + } + } + + // Allow other modules to alter the group view. + // Can't use module_invoke_all because we want + // to be able to use a reference to $node and $element. + foreach (module_implements('fieldgroup_view') as $module) { + $function = $module .'_fieldgroup_view'; + $function($node, $element, $group, $context); + } + + // Unset the original field values now that we've moved them. + foreach ($group['fields'] as $field_name => $field) { + if (isset($node->content[$field_name])) { + unset($node->content[$field_name]); + } } + + // The wrapper lets us get the themed output for the group + // to populate the $GROUP_NAME_rendered variable for node templates, + // and hide it from the $content variable if needed. + // See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper(). + $wrapper = array( + 'group' => $element, + '#weight' => $group['weight'], + '#post_render' => array('fieldgroup_wrapper_post_render'), + '#group_name' => $group_name, + '#type_name' => $node->type, + '#context' => $context, + ); + + $node->content[$group_name] = $wrapper; +} + +/** + * Render a single field group, fully themed with label. + * + * To be used by third-party code (Panels, ...) that needs to output an + * isolated field group. Do *not* use inside node templates, use the + * $GROUP_NAME_rendered variables instead. You can also use the 'simple' + * style format and override the template fieldgroup-simple.tpl.php. + * + * By default, the field group is displayed using the settings defined for the + * 'full node' or 'teaser' contexts (depending on the value of the $teaser param). + * Set $node->build_mode to a different value to use a different context. + * + * Different settings can be specified by adjusting $group['settings']['display']. + * + * @param $group + * The field group definition. + * @param $node + * The node containing the field group to display. Can be a 'pseudo-node', + * containing at least 'type', 'nid', 'vid', and the field data required + * for the group. + * @param $teaser + * @param $page + * Similar to hook_nodeapi('view'). + * @return + * The themed output for the field group. + * + * @see content_view_field() + */ +function fieldgroup_view_group($group, &$node, $teaser = FALSE, $page = FALSE) { + $group_name = $group['group_name']; + $field_types = _content_field_types(); + + // Clone the node to prevent from altering the original. + $node_copy = drupal_clone($node); + + // Use 'full'/'teaser' if not specified otherwise. + $node_copy->build_mode = isset($node_copy->build_mode) ? $node_copy->build_mode : NODE_BUILD_NORMAL; + + // Build the content element for individual fields in the field group. + if (!isset($node_copy->content)) { + $node_copy->content = array(); + } + foreach (array_keys($group['fields']) as $field_name) { + $field = content_fields($field_name, $node_copy->type); + + if (isset($node_copy->{$field_name})) { + $items = $node_copy->{$field_name}; + + // One-field equivalent to _content_field_invoke('sanitize'). + $module = $field_types[$field['type']]['module']; + $function = $module .'_field'; + if (function_exists($function)) { + $function('sanitize', $node_copy, $field, $items, $teaser, $page); + $node_copy->{$field_name} = $items; + } + + $field_view = content_field('view', $node_copy, $field, $items, $teaser, $page); + // content_field('view') adds a wrapper to handle variables and 'excluded' + // fields for node templates. We bypass it and get the actual field. + $node_copy->content[$field_name] = $field_view[$field_name]; + } + } + + // Build the content element of the field group itself. + fieldgroup_build_content($group, $node_copy, $teaser, $page); + + // fieldgroup_build_content() adds a wrapper to handle variables and 'excluded' + // groups for node templates. We bypass it and render the actual field group. + $output = drupal_render($node_copy->content[$group_name]['group']); + + return $output; } /** Index: modules/fieldgroup/panels/content_types/content_fieldgroup.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/modules/fieldgroup/panels/content_types/Attic/content_fieldgroup.inc,v retrieving revision 1.1.2.2 diff -u -p -r1.1.2.2 content_fieldgroup.inc --- modules/fieldgroup/panels/content_types/content_fieldgroup.inc 8 Jul 2009 23:23:30 -0000 1.1.2.2 +++ modules/fieldgroup/panels/content_types/content_fieldgroup.inc 10 Jul 2009 19:36:07 -0000 @@ -12,7 +12,7 @@ function fieldgroup_content_fieldgroup_ctools_content_types() { return array( 'title' => t('Content fieldgroup'), - 'defaults' => array('empty' => ''), + 'defaults' => array('label' => 'hidden', 'format' => 'simple', 'empty' => ''), ); } @@ -26,24 +26,24 @@ function fieldgroup_content_fieldgroup_c // The outer loop goes through each node type with groups. foreach (fieldgroup_groups() as $node_type_groups) { // The inner loop gives us each fieldgroup on each node type with groups. - foreach ($node_type_groups as $fieldgroup) { + foreach ($node_type_groups as $group) { // Skip field groups that are not of standard type. - if ($fieldgroup['group_type'] != 'standard') { + if ($group['group_type'] != 'standard') { continue; } // Name the content type a combination of fieldgroup and node type names. - $content_type_name = $fieldgroup['type_name'] . ':' . $fieldgroup['group_name']; + $content_type_name = $group['type_name'] . ':' . $group['group_name']; // Assemble the information about the content type. $info = array( 'category' => t('Content'), - 'title' => t('@group in @type (standard field group)', array( - '@group' => t($fieldgroup['label']), - '@type' => node_get_types('name', $fieldgroup['type_name']), + 'title' => t('field group: @group in @type', array( + '@group' => t($group['label']), + '@type' => node_get_types('name', $group['type_name']), )), 'description' => t('All fields from this field group on the referenced node.'), - 'required context' => new ctools_context_required(t('Node'), 'node', array('type' => array($fieldgroup['type_name']))), + 'required context' => new ctools_context_required(t('Node'), 'node', array('type' => array($group['type_name']))), ); $types[$content_type_name] = $info; @@ -63,49 +63,66 @@ function fieldgroup_content_fieldgroup_c $node = drupal_clone($context->data); // Extract the node type and fieldgroup name from the subtype. - list($node_type, $fieldgroup_name) = explode(':', $subtype, 2); + list($node_type, $group_name) = explode(':', $subtype, 2); // Get a list of all fieldgroups for this node type. $groups = fieldgroup_groups($node_type); - if (!isset($groups[$fieldgroup_name])) { + if (!isset($groups[$group_name])) { return; } + $group = $groups[$group_name]; - $group = $groups[$fieldgroup_name]; - $output = array(); - - foreach ($group['fields'] as $field_name => $field) { - $field = content_fields($field_name, $node_type); - $field_view = content_view_field($field, $node); - if (!is_null($field_view)) { - $output[] = $field_view; - } - } + // Render the field group. + $node->build_mode = NODE_BUILD_NORMAL; + $group['settings']['display']['label'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label']; + $group['settings']['display']['full']['format'] = $conf['format']; + $group['settings']['display']['full']['exclude'] = 0; + $output = fieldgroup_view_group($group, $node); $block = new stdClass(); - $block->title = $group['label']; - $block->content = !empty($output) ? theme('fieldgroup_content_type', $output, $node->nid) : $conf['empty']; - + if ($conf['label'] == 'normal') { + $block->title = t($group['label']); + } + $block->content = !empty($output) ? $output : $conf['empty']; return $block; } /** - * Allows users to theme the fieldgroup content type. - */ -function theme_fieldgroup_content_type($vars, $nid) { - return implode('', $vars); -} - -/** * Returns a settings form for the custom type. */ function fieldgroup_content_fieldgroup_content_type_edit_form(&$form, &$form_state) { $conf = $form_state['conf']; + $label_options = array( + 'normal' => t('Block title'), + 'above' => t('Above'), + ); + $form['label'] = array( + '#type' => 'select', + '#title' => t('Field group label'), + '#default_value' => !empty($conf['label']) && isset($label_options[$conf['label']]) ? $conf['label'] : 'hidden', + '#options' => $label_options, + '#description' => t('Configure how the field group label is going to be displayed. This option takes no effect when "Override title" option is enabled, the specified block title is displayed instead.'), + ); + + $format_options = array( + 'simple' => t('Simple'), + 'fieldset' => t('Fieldset'), + 'fieldset_collapsible' => t('Fieldset - Collapsible'), + 'fieldset_collapsed' => t('Fieldset - Collapsed'), + ); + $form['format'] = array( + '#type' => 'select', + '#title' => t('Field group format'), + '#default_value' => !empty($conf['format']) && isset($format_options[$conf['format']]) ? $conf['format'] : 'simple', + '#options' => $format_options, + '#description' => t('This option allows you to configure the field group format.'), + ); + $form['empty'] = array( '#type' => 'textarea', - '#title' => 'Empty text', + '#title' => t('Empty text'), '#description' => t('Text to display if group has no data. Note that title will not display unless overridden.'), '#rows' => 5, '#default_value' => $conf['empty'], @@ -123,5 +140,16 @@ function fieldgroup_content_fieldgroup_c * Admin title for fieldgroup content type. */ function fieldgroup_content_fieldgroup_content_type_admin_title($subtype, $conf, $context) { - return t('"@s" fieldgroup (@name)', array('@s' => $context->identifier, '@name' => $subtype)); + // Extract the node type and fieldgroup name from the subtype. + list($node_type, $group_name) = explode(':', $subtype, 2); + + // Get information about this field group for this node type. + $groups = fieldgroup_groups($node_type); + $group = $groups[$group_name]; + + return t('"@s" field group: @group in @type', array( + '@s' => $context->identifier, + '@group' => t($group['label']), + '@type' => node_get_types('name', $node_type), + )); }