Sorry for not making a patch file but here is the code to for supported/profile.php

function profile_node_import_fields($type) {
    if ($type !== 'user') return;

    $fields = array();
    $results = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight, title');
    while ($field = db_fetch_object($results)) {
        $name = $field->name;
        $fields[$name] = array(
            'title' => check_plain($field->title),
            'group' => check_plain($field->category),
            'map_required' => $field->required,);

        switch ($field->type) {
            case 'selection':
                $options = $field->required ? array() : array('--');
                $lines = split("[,\n\r]", $field->options);
                foreach ($lines as $line) {
                    if ($line = trim($line)) {
                        $options[$line] = $line;
                    }
                }

                $fields[$name]['allowed_values'] = $options;
                break;
            case 'date':
                $fields[$name]['input_format'] = 'date';
                break;
            case 'checkbox':
                $fields[$name]['is_checkboxes'] = true;
                break;
            default:
                break;
        }
    }

    return $fields;
}

Comments

Robrecht Jacques’s picture

Nice!

Will commit to CVS after a bit of testing tomorrow.

Not sure about the 'is_checkboxes'. I think it is just

            case 'checkbox':
                $fields[$name]['input_format'] = 'boolean';
                break;

because the checkbox is only one value: either on or off. The 'is_checkboxes' is meant for stuff where you want "published||promoted" to be converted into array('published' => 1, 'promoted' => 1) instead of an array of values (array(0 => 'published', 1 => 'promoted')).

Are those all field types? Or do the others not need additional stuff?

Does it make sense to implement hook_node_import_defaults()?

Never really used profile myself.

uniqueculture’s picture

Those are all field types currently supported by profile module. Profile module is hooked to the user module and puts imported data into the right place. Selection type fields can potentially create some issues... never tested those.

Profile field can also have different visibility settings. Defaults feature can apply to the fields that are:
* Only accessible by administrators, modules and themes.
* Content only available to privileged users.

or while mapping fields under each profile field there will be a "Provide a default value for the field" checkbox and the field is going to show up on defaults step.

Lastly, I'm planning to write some code for cck fields support. Should I start from group-up or I can somehow contribute to current developments?

Robrecht Jacques’s picture

Great you are going to follow up the profile support.

Do not provide a "Provide a default value for the field". I would prefer you just add all profile fields to the "Set default values" page. If the user fills in something, it will be used, otherwise it will be ignored.

I'm finishing the core CCK modules (Text, Number, Options, ...) right now and will commit before the end of the day. If you can build upon that (corrections, additional contrib CCK fields), that'd be great.

uniqueculture’s picture

I finally wrote "defaults" hook implementation:

/**
 * Implementation hook_node_import_defaults()
 *
 * @param string $type
 * @param array $defaults
 * @param array $fields
 * @param array $map
 * @return array
 */
function profile_node_import_defaults($type, $defaults, $fields, $map)
{
    if ($type !== 'user') return;

    $fields = array();
    $categories = profile_categories();
    foreach ($categories as $category) {
        // Call profile function and make it look like a legit call
        $form = profile_form_profile(array(), null, $category['name']);
        // Returned array has a category as fieldset
        foreach ($form[$category['name']] as $field => $info) {
            // Ignore fieldset params and grab only fields inside category fieldset
            if (strpos($field, '#') === 0 || !is_array($info)) continue;
            $fields[$field] = $info;
        }
    }

    return $fields;
}
Robrecht Jacques’s picture

Status: Needs review » Fixed

Committed to CVS. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.