Skip to content

Commit

Permalink
ContactForm: Make selected default channel's address field required
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jan 29, 2025
1 parent ede7734 commit c6bbd6c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions library/Notifications/Web/Form/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ protected function assemble()
[
'label' => $this->translate('Default Channel'),
'required' => true,
'class' => 'autosubmit',
'disabledOptions' => [''],
'options' => $channelOptions
]
Expand Down Expand Up @@ -402,23 +403,26 @@ private function fetchDbValues(): array
*/
private function addAddressElements(): void
{
$plugins = $this->db->fetchPairs(
AvailableChannelType::on($this->db)
->columns(['type', 'name'])
->assembleSelect()
);
$plugins = AvailableChannelType::on($this->db)
->columns(['type', 'name', 'channel.id'])
->execute();

if (empty($plugins)) {
if (! $plugins->hasResult()) {
return;
}

$selectedChannelId = (int) $this->getValue('contact')['default_channel_id'];

$address = new FieldsetElement('contact_address', ['label' => $this->translate('Addresses')]);
$this->addElement($address);

foreach ($plugins as $type => $label) {
foreach ($plugins as $plugin) {
$type = $plugin->type;

$element = $this->createElement('text', $type, [
'label' => $label,
'validators' => [new StringLengthValidator(['max' => 255])]
'label' => $plugin->name,
'validators' => [new StringLengthValidator(['max' => 255])],
'required' => $plugin->channel->id === $selectedChannelId
]);

if ($type === 'email') {
Expand Down

0 comments on commit c6bbd6c

Please sign in to comment.