@@ -122,21 +122,33 @@ protected function assemble()
122122 ]
123123 );
124124
125+ $ channelQuery = Channel::on ($ this ->db )
126+ ->columns (['id ' , 'name ' , 'type ' ]);
127+
128+ $ channelNames = [];
129+ $ channelTypes = [];
130+ foreach ($ channelQuery as $ channel ) {
131+ $ channelNames [$ channel ->id ] = $ channel ->name ;
132+ $ channelTypes [$ channel ->id ] = $ channel ->type ;
133+ }
134+
125135 $ defaultChannel = $ this ->createElement (
126136 'select ' ,
127137 'default_channel_id ' ,
128138 [
129139 'label ' => $ this ->translate ('Default Channel ' ),
130140 'required ' => true ,
141+ 'class ' => 'autosubmit ' ,
131142 'disabledOptions ' => ['' ],
132- 'options ' => ['' => sprintf (' - %s - ' , $ this ->translate ('Please choose ' ))]
133- + Channel::fetchChannelNames ($ this ->db ),
143+ 'options ' => [
144+ '' => sprintf (' - %s - ' , $ this ->translate ('Please choose ' ))
145+ ] + $ channelNames ,
134146 ]
135147 );
136148
137149 $ contact ->registerElement ($ defaultChannel );
138150
139- $ this ->addAddressElements ();
151+ $ this ->addAddressElements ($ channelTypes [ $ this -> getValue ( ' default_channel_id ' )] ?? null );
140152
141153 $ this ->addHtml (new HtmlElement ('hr ' ));
142154
@@ -410,9 +422,11 @@ private function fetchDbValues(): array
410422 /**
411423 * Add address elements for all existing channel plugins
412424 *
425+ * @param ?string $defaultType The selected default channel type
426+ *
413427 * @return void
414428 */
415- private function addAddressElements (): void
429+ private function addAddressElements (? string $ defaultType ): void
416430 {
417431 $ plugins = $ this ->db ->fetchPairs (
418432 AvailableChannelType::on ($ this ->db )
@@ -433,10 +447,11 @@ private function addAddressElements(): void
433447
434448 $ this ->addElement ($ address );
435449
436- foreach ($ plugins as $ type => $ label ) {
450+ foreach ($ plugins as $ type => $ name ) {
437451 $ element = $ this ->createElement ('text ' , $ type , [
438- 'label ' => $ label ,
439- 'validators ' => [new StringLengthValidator (['max ' => 255 ])]
452+ 'label ' => $ name ,
453+ 'validators ' => [new StringLengthValidator (['max ' => 255 ])],
454+ 'required ' => $ type === $ defaultType
440455 ]);
441456
442457 if ($ type === 'email ' ) {
0 commit comments