Friday 25 March 2011

Drupal - Content construction kit (CCK) field information

Hi,

Days ago I was in need for quick access to CCK field table information in order to query Drupal data base. So searching through CCK modules function library I found couple of ones;
1. content_fields() - returns information about content fields - see more for options - http://api.lullabot.com/content_fields
2. content_database_info() - returns database information about particular field - more goes here - http://api.lullabot.com/content_database_info
So having a bit of brainstorming I've created this small function -

/*
 * @type
 * node type to retrive fields for
 * retuns array with key(['field_name']) => 
 * array() database_info
 */
function get_all_field_info_cck ($type) {
$fields = content_fields(NULL, $type);
    if($type) {
        $fields_db_info_array = array();
            foreach ($fields as $field) {
                $fields_db_info_array[$field['field_name']] = 
 
content_database_info($field);
                }
            return $fields_db_info_array; 
                    // return an array of given type
        }
        else {
            return; // otherwise returns nothing
        }

    }

Anyway there are couple of posts (like this - http://drupal.org/node/531140), where developers are discussing this topic, so others faced this problem before too.
I hope this will help you in your Drupal developements as it helped me, moreover maybe it'll save you hours of Google(ing).

No comments:

Post a Comment