File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
src/Kris/LaravelFormBuilder/Fields Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,12 @@ protected function setupValue()
142142 }
143143
144144 if (($ value === null || $ value instanceof \Closure) && !$ isChild ) {
145- $ attributeName = $ this ->getOption ('property ' , $ this ->name );
145+ if ($ this instanceof EntityType) {
146+ $ attributeName = $ this ->name ;
147+ } else {
148+ $ attributeName = $ this ->getOption ('property ' , $ this ->name );
149+ }
150+
146151 $ this ->setValue ($ this ->getModelValueAttribute ($ this ->parent ->getModel (), $ attributeName ));
147152 } elseif (!$ isChild ) {
148153 $ this ->hasDefault = true ;
Original file line number Diff line number Diff line change @@ -794,6 +794,26 @@ public function it_can_use_model_property_to_set_value()
794794 $ this ->assertEquals ($ form ->alias_accessor ->getValue (), $ this ->model ->accessor );
795795 }
796796
797+ /** @test */
798+ public function it_sets_entity_field_value_to_the_entity_model_value ()
799+ {
800+ $ dummyModel = new DummyModel ();
801+ $ dummyModel ->id = 1 ;
802+
803+ $ this ->model ->dummy_model_id = $ dummyModel ->id ;
804+
805+ $ form = $ this ->formBuilder
806+ ->plain ([
807+ 'model ' => $ this ->model ,
808+ ])
809+ ->add ('dummy_model_id ' , 'entity ' , [
810+ 'class ' => DummyModel::class,
811+ 'property ' => 'name ' ,
812+ ]);
813+
814+ $ this ->assertEquals ($ form ->dummy_model_id ->getValue (), $ this ->model ->dummy_model_id );
815+ }
816+
797817 /** @test */
798818 public function it_reads_configuration_properly ()
799819 {
You can’t perform that action at this time.
0 commit comments