node_view does not make ['view'] s for the cck fields in content profiles
YesCT - April 2, 2009 - 20:35
| Project: | Content Profile |
| Version: | 6.x-1.0-beta3 |
| Component: | Base module |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
does node_view not work with cck fields in content profiles?
When I use ['value'], the stuff gets printed, but ['value'] is the bad way.
When I use ['view'], nothing gets printed.
like:
<?php
<hr>
<?php
if ( $node->field_districtadvisors[0]['uid'] == NULL) {
echo "<p> Currently, there are no DAs for this District. Contact the ACL.";
} else {
foreach ((array)$node->field_districtadvisors as $leader_item) {
echo "<h2>District Advisor</h2>";
echo "<p>";
print $leader_item['view'];
echo "<br>";
$new_leader_node = node_view(content_profile_load('profile', $leader_item['uid']));
//$new_leader_node = content_profile_load('profile', $leader_item['uid']);
// print name
echo "first name: ";
print $new_leader_node->field_firstname[0]['view']; echo " ";
// if (0 != strcmp($new_leader_node->field_firstname[0]['value'],"")) {
// print $new_leader_node->field_firstname[0]['value']; echo " "; }
....
?>What am I doing wrong?
Thanks.

#1
Hi Cathy,
node_view() returns the "HTML representation of the themed node", not an object structure that stores the values. In the API document, you'll notice that node_view() returns the output of theme('node').
If you want to access the individual field values, you shouldn't use node_view(). Try the line of code you commented out:
$new_leader_node = content_profile_load('profile', $leader_item['uid']);#2
JamesAn, Thanks so much. This does make more sense.
Is there another function that would theme a field for me?
So I could do something like my invented field_view below:
<?php$new_leader_node = content_profile_load('profile', $leader_item['uid']);
// print name
echo "first name: ";
print field_view($new_leader_node->field_firstname[0]['view']); echo " ";
?>
I'm asking because someone insisted it was really bad to use the
$new_leader_node->field_firstname[0]['value']
['value'] because of security.
Also, I was hoping that something like field_view would know about the permissions user roles have to view certain cck fields, and not other cck fields.
Thanks, CT
#3
CCK has the
content_view_fieldfunction. You can find its definition here http://api.audean.com/api/function/content_view_field/API+Reference.BUT: I think that you should download the latest DEV snapshot and read the README file:
#4
You can use
$new_leader_node->field_firstname[0]['value'], but you'll have to manually filter it with check_plain().So, just use:
print check_plain($new_leader_node->field_firstname[0]['view']);.#5
Thank you so much. I will look into that. I just felt like I didnt know what to search for!
#6
JamesAn (and others).
I had been using print check_plain($new_leader_node->field_firstname[0]['value']);
But someone told me that was "bad" that I would have to do my own permissions checking.
And it does seem like cck fields I restricted according to roles in the Admin were being displayed to anyone, even anonymous users. I thought that it was showing the cck fields to everyone because the "view" functions did permission checking, and I was not using the "view" ... so I was hoping that if I figured out the right way, the best practices way, well... that things would be better. :)
What do you think?
#7
http://drupal.org/project/contemplate
#8
Oy vey, this issue managed to slip past me and I've forgotten all about it. Let's see... permission checking.
Instead of
print check_plain($new_leader_node->field_firstname[0]['value']);try
$profile = content_types('profile');if(content_access('view', $profile['fields']['field_firstname'])) {
print check_plain($new_leader_node->field_firstname[0]['value']);
}
content_types($type)gets data about the content $type; in this case, we want information about the fields in our 'profile' type.content_access($op, $field, $user)checks if $user can do the $op (view or edit) on the $field, which is the array field definition given by content_types(). If $user is not specified, content_access() checks against the current user.#9
Thanks!
#10
Unless there's something else, I think we're done here. =)
#11
Automatically closed -- issue fixed for 2 weeks with no activity.