/** * Mostly the same as populate_defaults , except takes a model object as input, not an array, * and also sets the form's _model_object * @param EE_Base_Class $model_obj * @return void */ public function populate_model_obj($model_obj) { $model_obj = $this->_model->ensure_is_obj($model_obj); $this->_model_object = $model_obj; $defaults = $model_obj->model_field_array(); foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { $form_inputs = $this->inputs(); if (isset($form_inputs[$relation_name])) { if ($relation_obj instanceof EE_Belongs_To_Relation) { //then we only expect there to be one $related_item = $this->_model_object->get_first_related($relation_name); $defaults[$relation_name] = $related_item->ID(); } else { $related_items = $this->_model_object->get_many_related($relation_name); $ids = array(); foreach ($related_items as $related_item) { $ids[] = $related_item->ID(); } $defaults[$relation_name] = $ids; } } } $this->populate_defaults($defaults); }