Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace App\Notification;

use Ibexa\Contracts\Core\Repository\Values\Notification\Notification;
use Ibexa\Core\Notification\Renderer\NotificationRenderer;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;

class ListRenderer implements NotificationRenderer
{
protected Environment $twig;

protected RouterInterface $router;

protected RequestStack $requestStack;

public function __construct(Environment $twig, RouterInterface $router, RequestStack $requestStack)
{
$this->twig = $twig;
$this->router = $router;
$this->requestStack = $requestStack;
}

public function render(Notification $notification): string
{
$templateToExtend = '@ibexadesign/account/notifications/list_item.html.twig';
$currentRequest = $this->requestStack->getCurrentRequest();
if ($currentRequest && $currentRequest->attributes->getBoolean('render_all')) {
$templateToExtend = '@ibexadesign/account/notifications/list_item_all.html.twig';
}

return $this->twig->render('@ibexadesign/notification.html.twig', [
'notification' => $notification,
'template_to_extend' => $templateToExtend,
]);
}

public function generateUrl(Notification $notification): ?string
{
if (array_key_exists('content_id', $notification->data)) {
return $this->router->generate('ibexa.content.view', [
'contentId' => $notification->data['content_id'],
]);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Ibexa\Contracts\Core\Repository\Values\Notification\Notification;
use Ibexa\Core\Notification\Renderer\NotificationRenderer;
use Ibexa\Core\Notification\Renderer\TypedNotificationRendererInterface;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;

Expand All @@ -23,7 +24,10 @@ public function __construct(Environment $twig, RouterInterface $router)

public function render(Notification $notification): string
{
return $this->twig->render('@ibexadesign/notification.html.twig', ['notification' => $notification]);
return $this->twig->render('@ibexadesign/notification.html.twig', [
'notification' => $notification,
'template_to_extend' => $templateToExtend,
]);
}

public function generateUrl(Notification $notification): ?string
Expand All @@ -34,4 +38,16 @@ public function generateUrl(Notification $notification): ?string

return null;
}

}

public function getTypeLabel(): string
{
return /** @Desc("Workflow stage changed") */
$this->translator->trans(
'workflow.notification.stage_change.label',
[],
'ibexa_workflow'
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '@ibexadesign/account/notifications/list_item.html.twig' %}
{% extends template_to_extend %}

{% trans_default_domain 'custom_notification' %}

Expand Down
19 changes: 19 additions & 0 deletions code_samples/notifications/Src/Query/search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Ibexa\Contracts\Core\Repository\Values\NotificationQuery;

$repository = $this->getRepository();
$notificationService = $repository->getNotificationService();
$query = new NotificationQuery([], 0, 25);

$query->addCriterion(new Type('Workflow:Review'));
$query->addCriterion(new Status(['unread']));

$from = new \DateTimeImmutable('-7 days');
$to = new \DateTimeImmutable();

$query->addCriterion(new DateCreated($from, $to));

$notificationList = $notificationService->findNotifications($query);
14 changes: 13 additions & 1 deletion docs/administration/back_office/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ Example:
[[= include_file('code_samples/back_office/notifications/src/EventListener/ContentPublishEventListener.php') =]]
```

To display the notification, write a renderer and tag it as a service.
### Display single notification

To display a single notification, write a renderer and tag it as a service.

The example below presents a renderer that uses Twig to render a view:

Expand All @@ -83,6 +85,16 @@ Finally, you need to add an entry to `config/services.yaml`:
[[= include_file('code_samples/back_office/notifications/config/custom_services.yaml') =]]
```

### Display notification list

To display a list of notifications, expand the above renderer.

The example below presents a modified renderer that uses Twig to render a list view:

```php
[[= include_file('code_samples/back_office/notifications/src/Notification/ListRenderer.php') =]]
```

## Notification timeout

To define the timeout for hiding Back-Office notification bars, per notification type, use the `ibexa.system.<scope>.notifications.<notification_type>.timeout` [configuration key](configuration.md#configuration-files):
Expand Down
15 changes: 9 additions & 6 deletions docs/api/event_reference/other_events.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
description: Events that are triggered when working with bookmarks, notifications, settings, forms and others.
page_type: reference
month_change: true
---

# Other events
Expand All @@ -22,12 +23,14 @@ The following events refer to [notifications displayed in the user menu](notific

| Event | Dispatched by | Properties |
|---|---|---|
|`BeforeCreateNotificationEvent`|`NotificationService::createNotification`|`CreateStruct $createStruct`</br>`Notification|null $notification`|
|`CreateNotificationEvent`|`NotificationService::createNotification`|`Notification $notification`</br>`CreateStruct $createStruct`|
|`BeforeDeleteNotificationEvent`|`NotificationService::deleteNotification`|`Notification $notification`|
|`DeleteNotificationEvent`|`NotificationService::deleteNotification`|`Notification $notification`|
|`BeforeMarkNotificationAsReadEvent`|`NotificationService::markNotificationAsRead`|`Notification $notification`|
|`MarkNotificationAsReadEvent`|`NotificationService::markNotificationAsRead`|`Notification $notification`|
|[`BeforeCreateNotificationEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Events-Notification-BeforeCreateNotificationEvent.html)|[`NotificationService::createNotification`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-NotificationService.html#method_createNotification)|`CreateStruct $createStruct`</br>`Notification|null $notification`|
|[`CreateNotificationEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Events-Notification-CreateNotificationEvent.html)|[`NotificationService::createNotification`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-NotificationService.html#method_createNotification)|`Notification $notification`</br>`CreateStruct $createStruct`|
|[`BeforeDeleteNotificationEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Events-Notification-BeforeDeleteNotificationEvent.html)|[`NotificationService::deleteNotification`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-NotificationService.html#method_deleteNotification)|`Notification $notification`|
|[`DeleteNotificationEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Events-Notification-DeleteNotificationEvent.html)|[`NotificationService::deleteNotification`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-NotificationService.html#method_deleteNotification)|`Notification $notification`|
|[`BeforeMarkNotificationAsReadEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Events-Notification-BeforeMarkNotificationAsReadEvent.html)|[`NotificationService::markNotificationAsRead`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-NotificationService.html#method_markNotificationAsRead)|`Notification $notification`|
|[`MarkNotificationAsReadEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Events-Notification-MarkNotificationAsReadEvent.html)|[`NotificationService::markNotificationAsRead`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-NotificationService.html#method_markNotificationAsRead)|`Notification $notification`|
|[`BeforeMarkNotificationAsUnreadEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Events-Notification-BeforeMarkNotificationAsUnreadEvent.html)|[`NotificationService::markNotificationAsUnread`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-NotificationService.html#method_markNotificationAsUnread)|`Notification $notification`|
|[`MarkNotificationAsUnreadEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Events-Notification-MarkNotificationAsUnreadEvent.html)|[`NotificationService::markNotificationAsUnread`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-NotificationService.html#method_markNotificationAsUnread)|`Notification $notification`|

## Settings

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
description: Notification DateCreated Search Criterion
month_change: true
---

# Notification DateCreated Criterion

The `DateCreated` Search Criterion searches for notifications based on the date when they were created.

## Arguments

- `created` - date to be matched, provided as a `DateTimeInterface` object
- `operator` - optional operator string (GTE, LTE)

## Example

### PHP

```php hl_lines="19"
[[= include_file('code_samples/notifications/src/Query/Search.php') =]]
```
18 changes: 18 additions & 0 deletions docs/search/criteria_reference/notification_search_criteria.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
description: Notification Search Criteria
month_change: true
---

# Notification Search Criteria reference

Notification Search Criteria are only supported by Notification Search (`NotificationService::findNotifications`).

With these Criteria you can filter notifications by their notification creation date, notification status, and notification type.

## Notification Search Criteria

|Search Criterion|Search based on|
|-----|-----|
|[DateCreated](notification_datecreated_criterion.md)|Date and time when notification was created|
|[Status](notification_status_criterion.md)|Status of the notification|
|[Type](notification_type_criterion.md)|Type of the notification|
20 changes: 20 additions & 0 deletions docs/search/criteria_reference/notification_status_criterion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
description: Notification Status Search Criterion
month_change: true
---

# Notification Status Criterion

The `Status` Search Criterion searches for notifications based on notification status.

## Arguments

- `status` - Boolean value that represents the status of the notification

## Example

### PHP

```php hl_lines="14"
[[= include_file('code_samples/notifications/src/Query/Search.php') =]]
```
20 changes: 20 additions & 0 deletions docs/search/criteria_reference/notification_type_criterion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
description: Type Search Criterion
month_change: true
---

# Type Criterion

The `Type` Search Criterion searches for notifications by their types.

## Arguments

- `type` - string that represents the type of the notification, takes values defined in notification workflow

## Example

### PHP

```php hl_lines="13"
[[= include_file('code_samples/notifications/src/Query/Search.php') =]]
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Icon Twig functions enable referencing SVG icons in templates.
page_type: reference
month_change: false
month_change: true
---

# Icon Twig functions
Expand Down Expand Up @@ -181,6 +181,7 @@ The following icons are available out-of-the-box:
| ![error-icon](img/icons/error-icon.svg.png) | `error-icon` |
| ![error](img/icons/error.svg.png) | `error` |
| ![expand-left](img/icons/expand-left.svg.png) | `expand-left` |
| ![expand-right](img/icons/expand-right.png). | `expand-right` |
| ![explore](img/icons/explore.svg.png) | `explore` |
| ![events-collected](img/icons/events-collected.svg.png) | `events-collected` |
| ![facebook](img/icons/facebook.svg.png) | `facebook` |
Expand Down Expand Up @@ -254,6 +255,7 @@ The following icons are available out-of-the-box:
| ![logout](img/icons/logout.svg.png) | `logout` |
| ![maform](img/icons/maform.svg.png) | `maform` |
| ![mail](img/icons/mail.svg.png) | `mail` |
| ![mail-open](img/icons/mail-open.png) | `mail-open` |
| ![markup](img/icons/markup.svg.png) | `markup` |
| ![media-type](img/icons/media-type.svg.png) | `media-type` |
| ![media](img/icons/media.svg.png) | `media` |
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/templating/twig_function_reference/img/icons/mail.svg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ nav:
- UserCriterion: search/activity_log_search_reference/user_criterion.md
- Action Configuration Search Criteria: search/ai_actions_search_reference/action_configuration_criteria.md
- Discounts Search Criteria: search/discounts_search_reference/discounts_criteria.md
- Notification Search Criteria:
- Notification Search Criteria: search/criteria_reference/notification_search_criteria.md
- DateCreated: search/criteria_reference/notification_datecreated_criterion.md
- Status: search/criteria_reference/notification_status_criterion.md
- Type: search/criteria_reference/notification_type_criterion.md

- Sort Clause reference:
- General Sort Clauses:
- General Sort Clause reference: search/sort_clause_reference/sort_clause_reference.md
Expand Down