Skip to content

Commit 65928a3

Browse files
ContactForm: Show channels link if no channel exists
1 parent b2df1bd commit 65928a3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/Notifications/Web/Form/ContactForm.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DateTime;
88
use Icinga\Exception\Http\HttpNotFoundException;
9+
use Icinga\Module\Notifications\Common\Links;
910
use Icinga\Module\Notifications\Model\AvailableChannelType;
1011
use Icinga\Module\Notifications\Model\Channel;
1112
use Icinga\Module\Notifications\Model\Contact;
@@ -17,6 +18,7 @@
1718
use ipl\Html\Contract\FormSubmitElement;
1819
use ipl\Html\FormElement\FieldsetElement;
1920
use ipl\Html\HtmlElement;
21+
use ipl\Html\TemplateString;
2022
use ipl\Html\Text;
2123
use ipl\Sql\Connection;
2224
use ipl\Stdlib\Filter;
@@ -26,6 +28,8 @@
2628
use ipl\Web\Common\CsrfCounterMeasure;
2729
use ipl\Web\Compat\CompatForm;
2830
use ipl\Web\Url;
31+
use ipl\Web\Widget\ActionLink;
32+
use ipl\Web\Widget\EmptyStateBar;
2933

3034
class ContactForm extends CompatForm
3135
{
@@ -170,6 +174,15 @@ protected function assemble()
170174
->registerElement($defaultChannel)
171175
->decorate($defaultChannel);
172176

177+
if (empty($channelNames)) {
178+
$this->prependHtml(new EmptyStateBar(
179+
TemplateString::create(
180+
$this->translate('No channels available. Please create a {{#link}}channel{{/link}} first'),
181+
['link' => new ActionLink(null, Links::channels(), attributes: ['data-base-target' => '_next'])]
182+
)
183+
));
184+
}
185+
173186
$this->addAddressElements($channelTypes[$this->getValue('default_channel_id')] ?? null);
174187
$this->addHtml($defaultChannel);
175188
$this->addHtml(new HtmlElement(
@@ -190,6 +203,7 @@ protected function assemble()
190203
$this->translate('Save Changes')
191204
]
192205
);
206+
193207
if ($this->contactId !== null) {
194208
/** @var FormSubmitElement $deleteButton */
195209
$deleteButton = $this->createElement(

0 commit comments

Comments
 (0)