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 ?
Comment | File | Size | Author |
---|---|---|---|
#21 | fields-nuke-preprocess-367215-21.patch | 1.02 KB | bjaspan |
#17 | field_remove_exclude-367215-17.patch | 14.08 KB | yched |
#15 | field_remove_exclude-367215-15.patch | 14.08 KB | yched |
#13 | field_remove_exclude-367215-13.patch | 14.05 KB | yched |
#8 | field_remove_exclude-367215-7.patch | 13.81 KB | yched |
Comments
Comment #1
KarenS CreditAttribution: KarenS commentedIt'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.
Comment #2
yched CreditAttribution: yched commentedIt'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.
Comment #3
AmrMostafa CreditAttribution: AmrMostafa commentedhook_node_alter()
seems to be a 'by design' to me (regardless of whether we are talking about the oldhook_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 usehook_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?)
Comment #4
yched CreditAttribution: yched commentedI 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.
Comment #5
yched CreditAttribution: yched commentedSee #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.
Comment #6
yched CreditAttribution: yched commentedNow that #455844: Allow more granular theming of drupal_render'ed elements is in, we can remove that horror.
Comment #7
JohnAlbinOh, exclude checkbox, you served us well in D6. Now its time for you to die. +1
Comment #8
yched CreditAttribution: yched commentedForgot to remove the TODOs in node.tpl.php / user.tpl.php
Comment #9
webchickI do love so very much patches with lots and lots of - signs.
Comment #10
moshe weitzman CreditAttribution: moshe weitzman commentedYeah, it does feel good to rm dodgy code.
Comment #11
sun...
It seems the entire code for $wrapper can go.
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commentedCode like that makes me think of #theme_wrapper which is a new render property - see drupal_render() docs.
Comment #13
yched CreditAttribution: yched commentedUpdated 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 :-)
Comment #15
yched CreditAttribution: yched commentedRerolled.
Comment #17
yched CreditAttribution: yched commentedI think it's just the recent broken HEAD, but rerolled just to be sure.
Comment #18
moshe weitzman CreditAttribution: moshe weitzman commentedIt still feels good deleting all this code. I will reopen this patch whenever I am feeling down.
Comment #19
yched CreditAttribution: yched commentedLOL.
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.
Comment #20
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Yay!
Comment #21
bjaspan CreditAttribution: bjaspan commented'preprocess' is no longer a valid $op for _field_invoke(). I feel confident RTBC'ing my own patch for this. :-)
Comment #22
yched CreditAttribution: yched commented#21: indeed.
Cleaned the matching code in CCK UI.
Comment #23
Dries CreditAttribution: Dries commentedBold move, Barry, but committed to CVS HEAD. ;-)
Comment #25
lloydpearsoniv CreditAttribution: lloydpearsoniv commentedWas 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.
Comment #26
yched CreditAttribution: yched commentedThe '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