[development] How to list fields and types

nan wich nan_wich at bellsouth.net
Wed Jan 19 15:28:29 UTC 2011


>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'=> $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 <fernando at jaguaribe.net>
To: development at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110119/b2ad2d68/attachment.html 


More information about the development mailing list