I was wondering if i can create programmatically a CCK field instance and insert the "allowed_values" in a single stage. So i tried this:

 field_create_instance(array(
  'field_name' => 'card number',
  'entity_type' => 'payment_method',
  'bundle' => 'debit_card',
  'label' => t('Debit/Credit card'),
  'description' => t('Add card\'s number '),
  'widget' => array(
      'type' => 'options_select',
      'weight' => 0,
      'settings' => array('size' => 50),
   ),
  'required' => TRUE,
 ));

I've tried some cases i.e to set in 'settings' => array( 'allowed_values' => array( 1, 2, 3 ) ) but nothing happened. Any suggestions?

share|improve this question
1  
I think that needs to be an array of matching key/value pairs. Try array(1 => 1, 2 => 2, 3 => 3). You may also need this in your settings array: 'allowed_values_function' => '' – Charlie S Nov 20 '12 at 17:46
Thank you Charlie S. Your post was very usefull! – Thanos Nov 21 '12 at 8:56
Did that solve it? I can post as an answer below and be a bit more descriptive. – Charlie S Nov 21 '12 at 17:02
Yes, i solve it! Thanks a lot! But just to know, it worked for me when i moved my "allowed_values_function" callback in .module file. So if you want to scaffold your module set your callback inside .module file. – Thanos Nov 22 '12 at 15:58

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.