This is D6 code for the CCK API.
In D7, you can use field_info_instances('node').
foreach (field_info_instances('node') as $node_type => $instances) {
foreach ($instances as $instance) {
$field = field_info_field($field_name);
drupal_set_message(t('node type: %node_type, name: %field_name,
label: %label, type: %type',
array(
'%node_type' => $node_type,
'%field_name' => $field['field_name'],
'%label' => $instance['label'],
'%type' => $field['type'],
))
);
}
}
Le 19/01/2011 16:28, nan wich a écrit :
From the RealName module:
$all_fields = content_fields(NULL, $type);
if ($all_fields) {
foreach ($all_fields as $field_name => $field_attributes) {
// If it's not the type we are looking for, then skip the field.
if ($field_attributes['type_name'] != $type) {
continue;
}
switch ($field_attributes['type']) {
case 'text':
if ($field_attributes['multiple']) {
drupal_set_message(t('The RealName module does not
currently support fields with multiple values, such as @fld.',
array('@fld' <mailto:%27@fld%27>=> $field_name)), 'warning');
}
else {
$selected = array_key_exists($field_name, $current);
$fields[$field_name] = array(
'title' => $field_attributes['widget']['label'],
'weight' => $selected ? $current[$field_name] : 0,
'selected' => $selected,
);
}
break;
case 'link':
$links[$field_name] = $field_attributes['widget']['label'];
}
}
}
else {
drupal_set_message(t('The !type content type has no fields to
use.', array('!type' => $type)), 'error');
}
/*Nancy*/
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L.
King, Jr.
------------------------------------------------------------------------
*From:* Fernando Correa da Conceição <ferna...@jaguaribe.net>
*To:* development@drupal.org
*Sent:* Wed, January 19, 2011 9:59:17 AM
*Subject:* [development] How to list fields and types
I have a $node object, in this node there is some fields (Drupal 7).
The module works on all contents type, so i do not know what fields
the node have. I need to list all fields from a node and get the type
of field.
Someone can show a example how to do this please?
Thanks.