Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi,
I have a view where a bunch of fields is printed. Now I am trying to check if the current user has the the rights to access each field, but I think I don't understand the whole thing enough.
I have the correct $account and the $node variables, but I don't know what the function expects for the $field variable:
if (cck_private_fields_field_access('view', $field, $account, $node))
//print the field
Let's say the field is $data->node_users_node_data_field_benutzerbild_field_benutzerbild_field_icq_value, what's the correct parameter or how do I find it out?
Regards,
Raphael
Comments
Comment #1
markus_petrux CreditAttribution: markus_petrux commentedYou are not supposed to invoke
cck_private_fields_field_access()
directly. It will be invoked for you.This function is the implementation of
hook_field_access()
, which is invoked bycontent_access()
in CCK when checking access to each field. In Views, this will happen in 2 different stages:1) Each field is exposed to Views with an access callback, which is defined by CCK to be content_access function, and this is used by Views to see if the current user has access to view the field, but it uses this invocation just to include the field in the query. Here we grant access because views does not give us the $node. The query has not been executed yet.
2) View will use
content_format()
to render each field in the view, and here a $node object will be passed along.content_format()
invokescontent_access()
andcontent_access()
invokes our hook. This time we have the $node, so we can check if the current user is allowed to view this field based on privacy settings for that field.If you need to check access to a CCK field directly, for whatever reason, then you need to invoke
content_access('view', $field, $account, $node)
(implemented in content.module). Here,$field
is an array of settings about the field, as returned bycontent_fields($field_name, $type_name)
.Comment #2
markus_petrux CreditAttribution: markus_petrux commentedComment #4
maximer CreditAttribution: maximer commentedHi,
has anyone an example with the content_access() function ??
I don't know how to replace the variable $field. It's is the id of the field, the name ??
Thanks for your answers
Maxime
Comment #5
markus_petrux CreditAttribution: markus_petrux commentedLook at how this function is being used in CCK itself. There's no official documentation on CCK, so the best place to look at is the source code itself.
$field is often an array that contains field and widget settings information. You can get using content_fields($field_name, $type_name). But please, look at CCK source code. If you're writing custom code for you, that's the best source.