-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! IBX-8736: Allowed to sent user notification via symfony/notifier
- Loading branch information
Showing
10 changed files
with
188 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
imports: | ||
- { resource: services/channel.yaml } | ||
- { resource: services/mappers.yaml } | ||
- { resource: services/papi.yaml } | ||
- { resource: services/subscription_resolver.yaml } | ||
- { resource: services/system_notifications.yaml } |
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/bundle/Resources/config/services/system_notifications.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
Ibexa\Notifications\SystemNotification\SystemNotificationChannel: | ||
tags: | ||
- name: notifier.channel | ||
channel: ibexa | ||
|
||
Ibexa\Notifications\SystemNotification\SystemNotificationRenderer: | ||
tags: | ||
- name: ibexa.notification.renderer | ||
alias: system | ||
|
Empty file.
27 changes: 27 additions & 0 deletions
27
src/bundle/Resources/views/themes/admin/notification/system_notification.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends '@ibexadesign/account/notifications/list_item.html.twig' %} | ||
|
||
{% trans_default_domain 'ibexa_notification' %} | ||
|
||
{% block icon %} | ||
<span class="type__icon"> | ||
<svg class="ibexa-icon ibexa-icon--review"> | ||
<use xlink:href="{{ ibexa_icon_path(icon|default('info')) }}"></use> | ||
</svg> | ||
</span> | ||
{% endblock %} | ||
|
||
{% block notification_type %} | ||
<span class="type__text"> | ||
{{ subject|default('') }} | ||
</span> | ||
{% endblock %} | ||
|
||
{% block message %} | ||
{% embed '@ibexadesign/ui/component/table/table_body_cell.html.twig' with { class: 'ibexa-notifications-modal__description' } %} | ||
{% block content %} | ||
<p class="description__text"> | ||
{{ content|default('') }} | ||
</p> | ||
{% endblock %} | ||
{% endembed %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Notifications\SystemNotification; | ||
|
||
use Ibexa\Contracts\Notifications\Value\Recipent\UserRecipientInterface; | ||
use Ibexa\Core\MVC\Symfony\Routing\RouteReference; | ||
use Symfony\Component\Notifier\Notification\Notification; | ||
|
||
final class SystemNotification extends Notification implements SystemNotificationInterface | ||
{ | ||
private ?string $icon = null; | ||
|
||
private ?RouteReference $route = null; | ||
|
||
public function getIcon(): ?string | ||
{ | ||
return $this->icon; | ||
} | ||
|
||
public function setIcon(?string $icon): void | ||
{ | ||
$this->icon = $icon; | ||
} | ||
|
||
public function getRoute(): ?RouteReference | ||
{ | ||
return $this->route; | ||
} | ||
|
||
public function setRoute(?RouteReference $route): void | ||
{ | ||
$this->route = $route; | ||
} | ||
|
||
public function setContent(string $content): void | ||
{ | ||
$this->content($content); | ||
} | ||
|
||
public function asSystemNotification(UserRecipientInterface $recipient, ?string $transport = null): ?SystemMessage | ||
{ | ||
$context = [ | ||
'subject' => $this->getSubject(), | ||
'content' => $this->getContent(), | ||
]; | ||
|
||
if ($this->icon !== null) { | ||
$context['icon'] = $this->icon; | ||
} | ||
|
||
if ($this->route !== null) { | ||
$context['route_name'] = $this->route->getRoute(); | ||
$context['route_params'] = $this->route->getParams(); | ||
} | ||
|
||
return new SystemMessage($recipient->getUser(), $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Notifications\SystemNotification; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Notification\Notification; | ||
use Ibexa\Core\Notification\Renderer\NotificationRenderer; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Twig\Environment; | ||
|
||
final class SystemNotificationRenderer implements NotificationRenderer | ||
{ | ||
private const KEY_ICON = 'icon'; | ||
private const KEY_ROUTE_NAME = 'route_name'; | ||
private const KEY_ROUTE_PARAMS = 'route_params'; | ||
private const KEY_CONTENT = 'content'; | ||
private const KEY_SUBJECT = 'subject'; | ||
|
||
private Environment $twig; | ||
|
||
private UrlGeneratorInterface $urlGenerator; | ||
|
||
public function __construct(Environment $twig, UrlGeneratorInterface $urlGenerator) | ||
{ | ||
$this->twig = $twig; | ||
$this->urlGenerator = $urlGenerator; | ||
} | ||
|
||
public function render(Notification $notification): string | ||
{ | ||
return $this->twig->render( | ||
'@ibexadesign/notification/system_notification.html.twig', | ||
[ | ||
'icon' => $notification->data[self::KEY_ICON] ?? null, | ||
'content' => $notification->data[self::KEY_CONTENT] ?? null, | ||
'subject' => $notification->data[self::KEY_SUBJECT] ?? null, | ||
'notification' => $notification, | ||
'created_at' => $notification->created, | ||
] | ||
); | ||
} | ||
|
||
public function generateUrl(Notification $notification): ?string | ||
{ | ||
if (!isset($notification->data[self::KEY_ROUTE_NAME])) { | ||
return null; | ||
} | ||
|
||
return $this->urlGenerator->generate( | ||
$notification->data[self::KEY_ROUTE_NAME], | ||
$notification->data[self::KEY_ROUTE_PARAMS] ?? [] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters