I have a multistep form with mforms in forth step my form have fivestar field from a review node content type. All fivestar field display option are set to basic, but fields are displaying differently.

I tried to change the display widget in my module, with no luck. If i try to change the widget it returns to defaults.

Any suggestion are welcome. thx

function _reviewform_step4(&$form_state, &$next_step, $params) {

    $form = array();

    //attaching existing content type fields
    $review = new stdClass();
    $review->type = 'review'; //content type

    field_attach_form('node', $review, $form, $form_state);

    foreach ($form_state['field'] as $field) {
        if ($field['und']['field']['type'] == 'fivestar') {
            $field_name = $field['und']['field']['field_name'];
            // not working
            $form[$field_name]['und'][0]['rating']['#settings']['widget']['name'] = 'flames';
            $form[$field_name]['und'][0]['rating']['#settings']['widget']['css'] =     'sites/all/modules/fivestar/widgets/flames/flames.css';    
            // not working to
            $form[$field_name]['und'][0]['rating']['#widget']['name'] = 'flames';
            $form[$field_name]['und'][0]['rating']['#widget']['css'] = 'sites/all/modules/fivestar/widgets/flames/flames.css';    

enter image description here


I am not familiar with mforms, but I see a few potential issues:

1) your form doesn't have a standard signature ($form, &$form_state, ...). I obviously can't see how you're calling it, but this is not a typical thing to do.

2) when getting the path of the css, you should be using drupal_get_path https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#attached

3) widget is not a property of #settings

  • 1) mforms use this signature 2) Your right, but this is a debug/demo code 3) thx Thanks for your efforts. – zsd Jul 16 '14 at 8:06

Finally i used another concept. Instead of attaching all field with field_attach_form() i used

field_info_field(), field_info_instance() and field_default_form() to attache field one by one. Here i could override the instance widget settings.

 $rel_field = field_info_field('field_reliability');
 $rel_instance = field_info_instance('node', 'field_reliability', 'review');

 $rel_instance['widget']['settings']['widget']['fivestar_widget'] = drupal_get_path('module', 'fivestar') . 'widgets/flames/flames.css';

 $my_reliability = field_default_form('node', $review, $rel_field, $rel_instance, LANGUAGE_NONE, array(), $form, $form_state);
 $form['field_reliability'] = $my_reliability;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.