Posted by pentike on January 12, 2008 at 5:01pm
14 followers
| Project: | Content Construction Kit (CCK) |
| Version: | 6.x-2.9 |
| Component: | Documentation |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Hello!
I tried to make a custom theme that displays each field of my content in a tabular form as a name-value list. Unfortunately I realized, that the cck field label attribute does not appear in the $node object passed to the template.
I made this little patch to content.module in order to get my field labels, but since this was the first time I saw the module code, there may be a more elegant solution.
yours,
pentike
| Attachment | Size |
|---|---|
| content.module.diff | 722 bytes |
Comments
#1
This is a feature I need as well. I will try applying the patch and see if it works for me.
#2
When I apply this patch, the label item is indeed added to the
$nodeobject. However, something strange happens: node types that use the default CCK-generated body have serious rendering errors as soon as I apply the patch. I furthermore cannot get rid of the rendering errors simply by reverting the patch; I have to resubmit each and every node that uses the CCK-generated body so that the body goes back to the way it's supposed to be. (So: as usual, do not test this patch on production sites.)Here's an example of HTML for a field with the un-patched CCK body.
<div class="field field-type-text field-field-med-school"><div class="field-items">
<div class="field-item">
<div class="field-label-inline-first">
Medical school:
</div>
Medical College of Pennsylvania
</div>
</div>
</div>
When the patch is applied it immediately becomes:
<div class="field field-type-text field-field-med-school"><div class="field-items">
<div class="field-item">
<div class="field-label-inline-first">
Medical school:
</div>
Medical College of Pennsylvania
</div>
<div class="field-item">
<div class="field-label-inline">
Medical school:
</div>
M
</div>
</div>
</div>
It looks like CCK is treating the label as an additional field item, as if it were part of a list of multiple values. I am betting the text widget recursively uses something like
$field_items[$item_key][0]to get the text strings for multiple values, so that's why it's printing the first letter of the label as an additional field value.So, it looks like your solution is incompatible with the existing CCK text widget display (and possibly other field types that have multiple values). I will do some testing and see if I can come up with a better way to implement your change that will work with these widgets.
#3
I was able to resolve the bug by modifying your code slightly:
<?php
while ($value = db_fetch_array($result)) {
// MODIFIED BY XJM
$type_info = _content_type_info(FALSE);
$label_text = t($type_info['fields'][$field['field_name']]['widget']['label']);
$value['label_text'] = $label_text;
// END MODIFICATION
$additions[$field['field_name']][] = $value;
}
return $additions;
?>
This puts the label in the correct array.
I'll roll a revised patch and post it.
#4
Here's the patch. I made it against the 1.7 release version, but it should work just as well for 1.6 and the current dev build. Please review/test.
#5
NB: Same issue is at
http://drupal.org/node/181259
http://drupal.org/node/167539
#6
Tested xjm's patch and now it outputs field label when i use
<?phpprint $field_name[0]['label_text'];
?>
but the output is not localized. When i use
<?phpprint t($field_name[0]['label_text']);
?>
#7
I don't know much about how localization works... is there some reason that the localization would not be run until after this bit of code?
<?php$label_text = t($type_info['fields'][$field['field_name']]['widget']['label']);
$value['label_text'] = $label_text;
?>
Is there anything wrong with the code above?
#8
Just like to say I would find this useful. Much better than hardcoding labels into node.tpl.php files.
#9
And now I see that it's present in the 6.x version!
#10
Patch is still required for this functionality in the 5.x version (most recent is 1.10) which is the version the issue was created for.
#11
Sorry!
#12
I don't get it - psynaptic says it's fixed for 6.x-2.1, but now I updated to 6.x-2.3 and there is still no "label" data...
How could this be done?
#13
The patch above is specific to the Drupal 5 version of CCK. If the labels are present in the 6.x version of the $node object, well and good. If not, then the patch would need to be ported to the 6.x version or a new patch created.
#14
In 6.x it is possible to print labels in this way:
print $node->content['']['field']['#title']
#15
Please, see #637636: How to print the field label in node templates.
#16
Automatically closed -- issue fixed for 2 weeks with no activity.
#17
Yep, I learnd that from http://www.davidnewkerk.com/book/30
<?php print $node->content['field_name']['field']['#title'] ?>to print labels and if your fields are part of a group then use
<?php print $node->content['group_name']['group']['field_name']['field']['#title'] ?>Cheers.
#18
This still kinda sucks though. Ideally, it would be best to have the fully rendered field in the node object including the label and its formatting set in the CCK UI.
Sorry to re-open but I think a new feature request is the right outcome from this point.
#19
Is there still no way to call the field label of a cck field in node - view ?
The above suggested
<?phpprint $node->content['fieldname']['field']['#title']
?>
a print_r($node) also reveals the labels are not available in the node object.
#21
Where i can find the solution for this issue?
I want to print the label or the best solution for me is to print the entire CCK Field with label, items, display settings
#22
FuXXz you can try with: <? print $node->content['#content_extra_fields']['title']['label']; ?>
In $node->content['#content_extra_fields'] you will find all fields and their labels.
#23
<?phpprint $node->content['field_name']['field']['#title']
?>
This works fine, but not if the field is inside a CCK fieldgroup. In this case try ...
<?phpprint $node->content['group_name']['group']['field_name']['field']['#title']
?>
EDIT: sorry, duplicated entry see #17
#24
#17 worked for me (Thanks, filmoreha!). Echo #18.