The 'exclude' display setting has been introduced in CCK D6. It's a helper for more flexible node (fieldable entity) templating, which allows admins to specify that a field output should not end up in the $content variable, so themers can use both individual $FIELD_NAME_rendered variables for for fine-tuned parts of the node (entity), and $content for 'all the rest'.

Technically, this doesn't *need* to live in core, it can be entirely supported by CCK as an 'advanced display property'.

However, I recently noticed an annoying consequence of 'excluded' fields : they get out of hook_nodeapi_alter() treatment - which only deals with the drupal_rendered output of $node->content - hook_nodeapi_alter :

Fiter, substitute or otherwise alter the $node's raw text.
The $node->content array has been rendered, so the node body or teaser is filtered and now contains HTML. This hook should only be used when text substitution, filtering, or other raw text operations are necessary.

Meaning, marking a field as 'excluded' should just be a themeing facility, but it can break functionality.

Not sure what to do with that. Maybe this is precisely the reason why the feature should live in core, so that we can change node.module to *also* run nodeapi_alter on the output of 'excluded' fields ?
OTOH, the situation of nodeapi_alter() in current HEAD seems uncertain : #367214: hook_node_alter almost disappeared ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KarenS’s picture

It's easy for the core field code to allow for this, but quite a bit more complicated for an external module to provide. At least thinking through what CCK would have to do to provide this looks a lot more complicated to me. We have precedents for items that core handles mostly as a convenience to other modules (like some hook_devel stuff and various features that are not used by core at all) so I don't think that's a bad thing.

But conceptually I think core needs a way to reliably render individual fields as well as the whole node content array. Or maybe things like filters need to be run at the field level instead of the node level. Either way, we may need to do some re-thinking of the core processing.

yched’s picture

It's easy for the core field code to allow for this, but quite a bit more complicated for an external module to provide
I don't see why. It's just alter-adding '#post_render' => array('field_wrapper_post_render') to the render array.
IMO, the question here is : is this something a module that creates field definitions in its hook_install would need ?
The 'exclude' feature is strictly tied to how you theme your nodes, so I'd tend to think this is a site-admin choice only.

core needs a way to reliably render individual fields as well as the whole node content array
It does have that, that's the $FIELD_NAME_RENDERED variables, and field_view_field() function. Those do belong in core.

filters need to be run at the field level instead of the node level
No problem with that, that's the case already. Filters are run in check_markup(), which is run by field types during field_attach_view(). The problem I ran into involves the 'alter' nodeapi step, which happens after filter processing. And right, I'm wondering if this needs to be ran field by field for 'excluded' fields - in which case it might be easier to do in core.

AmrMostafa’s picture

hook_node_alter() seems to be a 'by design' to me (regardless of whether we are talking about the old hook_node_alter() or what I think replaces it now, hook_preprocess_node()). It's just by definition that these hooks act on the rendered node as handed out by node module(s), the theme is always able to add more stuff later on, so modules should not rely on it for doing critical operations. I think that modules should even use hook_pager_alter() instead if catching absolutely everything is what they want.

For 'exclude' implementation, can't this just be a dummy formatter which doesn't do anything? :)

(Btw, can't the 'hidden' display type be used for that?)

yched’s picture

I have to confess I'm not too clear on the exact uses cases for hook_node_alter(), and its status wrt hook_preprocess_node / hook_page_alter.
We'd need to see what comes out of #367214: hook_node_alter almost disappeared ?.

Just to clarify: "exclude" is not equivalent to 'dummy formatter' or 'hidden field'. We want the field rendered with the formatter defined in the display settings, but do not want the output garbled in the all-inclusive $content template variable.
It's really just a sore hack around the fact that drupal_render() doesn't offer enough granularity for flexible theming.

yched’s picture

Status: Active » Postponed

See #455844: Allow more granular theming of drupal_render'ed elements for a proposal that should let us get rid of both $FIELD_NAME_rendered variables and the 'exclude' stuff.
IMO, there's no fixing 'exclude' other that simply getting rid of it. It's an awful hack.

yched’s picture

Title: 'exclude from $content' display setting » Remove 'exclude from $content' display setting
Status: Postponed » Needs review
FileSize
11.85 KB
JohnAlbin’s picture

Oh, exclude checkbox, you served us well in D6. Now its time for you to die. +1

yched’s picture

Forgot to remove the TODOs in node.tpl.php / user.tpl.php

webchick’s picture

I do love so very much patches with lots and lots of - signs.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Yeah, it does feel good to rm dodgy code.

sun’s picture

Status: Reviewed & tested by the community » Needs work
+++ modules/field/field.default.inc	18 Jun 2009 23:59:53 -0000
@@ -194,60 +195,13 @@
     // See 'preprocess' op and theme_content_field_wrapper().
     $wrapper = $info + array(
       'field' => $element,
-      '#weight' => $instance['weight'],
-      '#post_render' => array('field_wrapper_post_render'),
-      '#context' => $context,
     );
 
-    $addition = array($field['field_name'] => $wrapper);
+    $addition = array($field['field_name'] => $element);
   }
   return $addition;
 }

...

    // The wrapper lets us get the themed output for the whole field
    // to populate the $FIELD_NAME_rendered variable for templates,
    // and hide it from the $content variable if needed.
    // See 'preprocess' op and theme_content_field_wrapper().
    $wrapper = $info + array(
      'field' => $element,
      '#weight' => $instance['weight'],
      '#post_render' => array('field_wrapper_post_render'),
      '#context' => $context,
    );

    $addition = array($field['field_name'] => $wrapper);

It seems the entire code for $wrapper can go.

moshe weitzman’s picture

Code like that makes me think of #theme_wrapper which is a new render property - see drupal_render() docs.

yched’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
14.05 KB

Updated for sun's comment in #11, which is completely true. I thought I removed that part altogether.

re Moshe: what was needed was rather a wrapping element in the render structure, I'm not sure that was related to #theme_wrapper and theming order.
Anyway, it's no longer needed now :-)

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
14.08 KB

Rerolled.

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
14.08 KB

I think it's just the recent broken HEAD, but rerolled just to be sure.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

It still feels good deleting all this code. I will reopen this patch whenever I am feeling down.

yched’s picture

LOL.
Actually I set back to CNR for the bot, but I think it tests RTBC patches as well, right ?

Let's get this in, there is related cleanup to do in the UI.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Yay!

bjaspan’s picture

Status: Fixed » Reviewed & tested by the community
FileSize
1.02 KB

'preprocess' is no longer a valid $op for _field_invoke(). I feel confident RTBC'ing my own patch for this. :-)

yched’s picture

#21: indeed.

Cleaned the matching code in CCK UI.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Bold move, Barry, but committed to CVS HEAD. ;-)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

lloydpearsoniv’s picture

Was it really necessary to remove exclude especially when there is absolutely no D7 module that provides this functionality? There are use cases where the exclude field saves alot of headache. Now i am stuck trying to figure out another option & I dont even know where to start.

yched’s picture

The 'exclude' feature (or rather, "horrible hack") has been fully replaced and deprecated by the much more flexible render() / show() / hide() functions in tpl files.
See http://drupal.org/update/themes/6/7#granular