0

I'm trying to set up a default value programmatically to my field which is in field collection. This has proved quite hard and I cant seem to get around it. Any assistance will be appreciated. This is the code i have tried to far without any success.This field is a select list with different select items. Now i want it to pre-select one of the items.

$field_collect = $form["field_fielc_collection_group"][LANGUAGE_NONE]; 

                            foreach ($field_collect as $fielders){
                                        if(is_array($fielders)){
                                        $somethin = $fielders["field_to_set_default"][LANGUAGE_NONE]["#default_value"];
                                        $default_val =array(t('something'));
                            array_push($somethin,$default_val); 

1 Answer 1

0

This is how I resolved this.

$language = $form['field_fielc_collection_group']["#language"];
                    $iterates = $form['field_fielc_collection_group'][$language];

                foreach($iterates as $multi__key => $iterate){
                            if (is_integer($multi__key)){
                                        if(is_array($iterate)){
                                            $delt = $form['field_fielc_collection_group'][$language][$multi__key]["#delta"];
$form["field_fielc_collection_group"][$language][$multi__key]["field_to_set_default"][$language]["#default_value"][$delt] = 'default_value' ;
                                        }
                            }
                }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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