0

For some reason my allowed_values_function never gets called when showing a field on a user bundle. Code:

function get_business_units()
{
    $options = entity_load('business_unit', FALSE, NULL, FALSE);
    $opt = bu_to_list_values($options);
    return $opt;
}


function MYMODULE_enable()
{
    if (!field_info_field('field_user_business_unit')) {
        $field = array(
            'field_name' => 'field_user_business_unit', 
            'type' => 'text', 
            'settings' => array(
                'allowed_values' => array(),
                'allowed_values_function' => 'get_business_units',
            )
        );
        field_create_field($field);

        // Create the instance on the bundle.
        $instance = array(
            'field_name' => 'field_user_business_unit', 
            'entity_type' => 'user', 
            'label' => 'Business Unit', 
            'bundle' => 'user', 
            'required' => FALSE,
            'settings' => array(
                'user_register_form' => 1,
        ),
            'widget' => array(
                'type' => 'options_select',
        ),
        );
        field_create_instance($instance);
    }
}

The field is created, and even displayed on the users "edit" page when editing their info. But the only value is "Select" or "None". My method is never called (I even placed a debug point). This is all in MYMODULE.install file.

4

3 回答 3

1

问题是:'type' => 'text'

你必须使用:'type' => 'list_text'

允许的值对于文本类型没有意义。

于 2015-05-21T11:30:39.640 回答
0

您的get_business_units()函数需要在MYMODULE.module文件中;这些.install文件不包含在正常的 Drupal 引导程序中。

于 2012-04-10T00:20:30.637 回答
0

您是否尝试过 drush features-revert MYMODULE ?

于 2013-02-07T19:21:52.527 回答