? cck_exclude_from_content-300368-16.patch ? cck_exclude_from_content-300368-17.patch Index: content.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.module,v retrieving revision 1.301.2.70 diff -u -p -r1.301.2.70 content.module --- content.module 9 Oct 2008 00:24:49 -0000 1.301.2.70 +++ content.module 9 Oct 2008 15:38:20 -0000 @@ -118,6 +118,15 @@ function content_menu() { 'type' => MENU_LOCAL_TASK, 'weight' => 2, ); + $items['admin/content/node-type/'. $type_url_str .'/theme'] = array( + 'title' => 'Theme fields', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('content_theme_exclusions_form', $type_name), + 'access arguments' => array('administer content types'), + 'file' => 'includes/content.admin.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + ); $contexts = content_build_modes('_tabs'); foreach ($contexts as $key => $tab) { $items['admin/content/node-type/'. $type_url_str .'/display/'. $key] = array( @@ -200,6 +209,9 @@ function content_theme() { 'path' => $path, 'arguments' => array('form' => NULL), ), + 'content_excluded_fields' => array( + 'arguments' => array(), + ), 'content_view_multiple_field' => array( 'arguments' => array('items' => NULL, 'field' => NULL, 'data' => NULL), ), @@ -738,11 +750,16 @@ function content_field($op, &$node, $fie } // The wrapper lets us get the themed output for the whole field - // once the $node->content has been rendered. - // See op 'preprocess_node' below. + // to populate the $FIELD_NAME_rendered variable for node templates, + // and hide it from the $content variable if needed. + // See 'preprocess_node' op and theme_content_field_wrapper()? $wrapper = array( 'field' => $element, '#weight' => $field['widget']['weight'], + '#post_render' => array('content_field_wrapper_post_render'), + '#field_name' => $field['field_name'], + '#type_name' => $node->type, + '#context' => $context, ); $addition = array($field['field_name'] => $wrapper); @@ -2024,6 +2041,75 @@ function content_default_value(&$form, & return (array) $default_value; } + /** + * Hide specified fields from the $content variable in node templates. + */ +function content_field_wrapper_post_render($content, $element) { + $excluded = theme('content_excluded_fields', $element['#type_name'], $element['#context']); + if (in_array($element['#field_name'], (array) $excluded)) { + $content = ''; + } + return $content; +} + +/** + * 'Theme' function. + * + * Lists fields and fieldgroups that should be excluded from + * the all-inclusive $content variable in node templates. + * The html for those are available in the $FIELD_NAME_rendered and + * $GROUP_NAME_rendered variables. + * This allows more flexibility in node templates : you can use custom markup + * around a few specific fields, and print the rest of the node with $content. + * + * @param $type_name + * The content-type of the node that is being rendered. + * + * @param $context + * The context for which the node is being rendered. + * Can be one of the following values : + * - 'teaser' + * - 'full' + * - NODE_BUILD_SEARCH_INDEX + * - NODE_BUILD_SEARCH_RESULT + * - NODE_BUILD_RSS + * - NODE_BUILD_PRINT + * + * @return + * A PHP array, listing the fields and groups that should be excluded from $content. + * Example : + * switch ($type_name) : + * case 'story': + * return array('field_foo', 'group_bar'); + * case 'page': + * return array('field_baz'); + * ); + */ +function theme_content_excluded_fields($type_name, $context) { + $exclusions = variable_get('cck_theme_exclusions_'. $type_name, array()); + if (isset($exclusions[$context])) { + return $exclusions[$context]; + } + return array(); +} + +/** + * Load the node contexts as an array of values. + * + * @return + * An associative array of contexts. + */ +function content_get_theme_contexts() { + return array( + 'teaser' => t('Node teaser'), + 'full' => t('Node page view'), + NODE_BUILD_SEARCH_INDEX => t('Search indexing'), + NODE_BUILD_SEARCH_RESULT => t('Search results'), + NODE_BUILD_RSS => t('RSS output'), + NODE_BUILD_PRINT => t('Printer output'), + ); +} + /** * Theme preprocess function for field.tpl.php. * @@ -2307,4 +2393,4 @@ function content_inactive_fields($type_n return $inactive[$type_name]; } return $inactive; -} \ No newline at end of file +} Index: includes/content.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/includes/content.admin.inc,v retrieving revision 1.181.2.50 diff -u -p -r1.181.2.50 content.admin.inc --- includes/content.admin.inc 8 Oct 2008 20:01:25 -0000 1.181.2.50 +++ includes/content.admin.inc 9 Oct 2008 15:38:23 -0000 @@ -1120,7 +1120,7 @@ function content_field_edit_form(&$form_ if (is_array($additions)) { $form['field'] = array_merge($form['field'], $additions); } - + $form['submit'] = array( '#type' => 'submit', '#value' => t('Save field settings'), @@ -1785,4 +1785,90 @@ function content_field_replace($nid, $up } node_save($node); return $node; -} \ No newline at end of file +} + + +/** + * Menu callback; presents a listing of fields theme settings for a content type. + * + * Form includes form widgets to select which fields should be removed from + * $node->content before theming occurs. + */ +function content_theme_exclusions_form(&$form_state, $type_name) { + content_inactive_message($type_name); + + // Gather type information. + $type = content_types($type_name); + $field_types = _content_field_types(); + $fields = $type['fields']; + + if (empty($fields)) { + drupal_set_message(t("There are no fields configured for this content type. You can add new fields on the !link page.", array( + '!link' => l(t('Manage fields'), 'admin/content/node-type/'. $type['url_str'] .'/fields'))), 'warning'); + return $form; + } + + $form['type_name'] = array( + '#type' => 'value', + '#value' => $type_name, + ); + + $form['exclusions'] = array( + '#tree' => TRUE, + '#value' => t('For each field, you may select the theme context in which the field output should not be included in the $content output to the theme. This feature allows themers to have more fine-grained control of content display.'), + ); + + $theme_options = content_get_theme_contexts(); + $theme_defaults = variable_get('cck_theme_exclusions_'. $type_name, array()); + $default_values = array(); + // It is easier for themers to handle the variable as a context-based array, so + // we have to transpose that to a field-based array for this form. + if (!empty($theme_defaults)) { + foreach ($theme_defaults as $context => $exclusions) { + if(!empty($exclusions)) { + foreach ($exclusions as $exclusion) { + $default_values[$exclusion][] = $context; + } + } + } + } + foreach ($fields as $field) { + $form['exclusions'][$field['field_name']] = array( + '#type' => 'checkboxes', + '#title' => $field['widget']['label'], + '#options' => $theme_options, + '#default_value' => (isset($default_values[$field['field_name']])) ? $default_values[$field['field_name']] : array(), + ); + } + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save theme settings'), + ); + $form['reset'] = array( + '#type' => 'submit', + '#value' => t('Reset to defaults'), + ); + return $form; +} + +function content_theme_exclusions_form_submit($form, &$form_state) { + // If a submit action, set the variable. + if ($form_state['values']['op'] == $form_state['values']['submit']) { + $data = $form_state['values']['exclusions']; + $exclusions = array(); + foreach ($data as $field => $settings) { + $settings = array_filter($settings); + if (!empty($settings)) { + foreach ($settings as $context) { + $exclusions[$context][] = $field; + } + } + } + variable_set('cck_theme_exclusions_'. $form_state['values']['type_name'], $exclusions); + drupal_set_message(t('Theme settings updated.')); + return; + } + // On reset, clear the variable. + variable_del('cck_theme_exclusions_'. $form_state['values']['type_name']); + drupal_set_message(t('Theme settings reset.')); +} Index: modules/fieldgroup/fieldgroup.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/modules/fieldgroup/fieldgroup.module,v retrieving revision 1.79.2.34 diff -u -p -r1.79.2.34 fieldgroup.module --- modules/fieldgroup/fieldgroup.module 6 Oct 2008 15:11:39 -0000 1.79.2.34 +++ modules/fieldgroup/fieldgroup.module 9 Oct 2008 15:38:25 -0000 @@ -573,12 +573,17 @@ function fieldgroup_nodeapi(&$node, $op, } } - // The wrapper lets us get the themed output for the whole group - // once the $node->content has been rendered. - // See fieldgroup_preprocess_node(). + // 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; @@ -587,6 +592,17 @@ function fieldgroup_nodeapi(&$node, $op, } } +/** + * Hide specified fields from the $content variable in node templates. + */ +function fieldgroup_wrapper_post_render($content, $element) { + $excluded = theme('content_excluded_fields', $element['#type_name'], $element['#context']); + if (in_array($element['#group_name'], (array) $excluded)) { + $content = ''; + } + return $content; +} + /* * Get the group name for a field. * If the field isn't in a group, FALSE will be returned.