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.

Jack
  • 9,156
  • 4
  • 50
  • 75

3 Answers3

1

The problem is: 'type' => 'text'.

You have to use: 'type' => 'list_text'.

Allowed values is meaningless for a text type.

JohnnyQ
  • 1,591
  • 1
  • 16
  • 25
0

Your get_business_units() function needs to be in the MYMODULE.module file; the .install files aren't included in a normal Drupal bootstrap.

Clive
  • 36,918
  • 8
  • 87
  • 113
  • That's what I thought originally also, but it still never gets called. I moved get_business_units() to MYMODULE.module file but no go. Cleared cache. I can execute php code with devel and it gets called. Is something wrong with my $field structure? Should the settings be defined at the instance or widget level? – Jack Apr 10 '12 at 03:28
  • Can you think of anything else? I have a month left to finish my Computer Science Capstone project and this puts a halt on [a lot] of functionality. – Jack Apr 12 '12 at 13:09
0

Have you tried drush features-revert MYMODULE ?

ARA1307
  • 1,022
  • 10
  • 13