drupal form field not loading correct data -


i building first drupal 7 module , having trouble screen edit fieldable entity. using field_attach_form , working great accept 1 field displaying field default rather current content of field entity.

i have text field, number field, number of boolean fields , 1 list_text field failing.

any ideas doing incorrectly? code below think needed please let me know if need more.

code create field in hook_enable:

if (!field_info_field('field_available')) {     $field = array (       'field_name' => 'field_available',       'type' => 'list_text',       'settings' => array(       'allowed_values' => array('no', 'provisionally', 'yes'),     ),  );  field_create_field($field); 

code create instance, in hook_enable:

 if (!field_info_instance('appointments_status', 'field_available', 'appointments_status')) {    $instance = array(      'field_name' => 'field_available',      'entity_type' => 'appointments_status',      'bundle' => 'appointments_status',      'label' => t('available?'),      'required' => true,      'default_value' => array(array('value' => 'no')),      'description' => t('set no if appointments status make slot unavailable, provisionally means reserve space temporarily'),    );  field_create_instance($instance); 

this entity has 1 bundle same name entity.

the code create url in hook_menu:

 $items['admin/appointments/appointments_statii/%/edit'] = array(    'title' => 'edit appointment status',    'description' => 'edit parameters of selected status code',    'page callback' => 'drupal_get_form',    'page arguments' => array('appointments_status_edit_form',3),    'access arguments' => array('access administration pages'),    'type' => menu_callback,  ); 

the form function is:

 function appointments_status_edit_form($form, &$form_state) {    // status id form_state args    $status_id = $form_state['build_info']['args'][0];     // load chosen status entity    $status = entity_load_single('appointments_status', $status_id);     // set fields form    field_attach_form('appointments_status', $status, $form, $form_state);     $form['submit'] = array(      '#type' => 'submit',      '#value' => 'save changes',      '#weight' => 99,    );    return $form;  } 

i have used devel module's dpm check data loaded correctly entity_load_single , is.

thanks rory

i have answered own question! programmatically loading entities , not loading field numbers list_text field stores, instead loading visual text. used metadata wrapper , code looked this:

$w_appointments_status->$appointments_availability= 'yes'; 

i changed to:

$w_appointments_status->$appointments_availability = 2; 

in example 'yes' third allowed value - hence 2. code in question in fact correct although have since added 'widget' , 'formatter' parameters instance.

i sorry if got of scratching heads thinking ' code correct'!! regards rory


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -