diff --git a/code_samples/back_office/notifications/src/Notification/ListRenderer.php b/code_samples/back_office/notifications/src/Notification/ListRenderer.php new file mode 100644 index 0000000000..7bef669299 --- /dev/null +++ b/code_samples/back_office/notifications/src/Notification/ListRenderer.php @@ -0,0 +1,52 @@ +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; + } +} diff --git a/code_samples/back_office/notifications/src/Notification/MyRenderer.php b/code_samples/back_office/notifications/src/Notification/MyRenderer.php index cb745cf6ab..0ed286c4ae 100644 --- a/code_samples/back_office/notifications/src/Notification/MyRenderer.php +++ b/code_samples/back_office/notifications/src/Notification/MyRenderer.php @@ -23,7 +23,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 diff --git a/code_samples/back_office/notifications/templates/themes/admin/notification.html.twig b/code_samples/back_office/notifications/templates/themes/admin/notification.html.twig index bf3f26b6f0..05f1448ee2 100644 --- a/code_samples/back_office/notifications/templates/themes/admin/notification.html.twig +++ b/code_samples/back_office/notifications/templates/themes/admin/notification.html.twig @@ -1,4 +1,4 @@ -{% extends '@ibexadesign/account/notifications/list_item.html.twig' %} +{% extends template_to_extend %} {% trans_default_domain 'custom_notification' %} diff --git a/code_samples/notifications/Src/Query/search.php b/code_samples/notifications/Src/Query/search.php new file mode 100644 index 0000000000..d771b8b343 --- /dev/null +++ b/code_samples/notifications/Src/Query/search.php @@ -0,0 +1,19 @@ +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); diff --git a/docs/administration/back_office/notifications.md b/docs/administration/back_office/notifications.md index fdf5f0cc0c..ceef60186f 100644 --- a/docs/administration/back_office/notifications.md +++ b/docs/administration/back_office/notifications.md @@ -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: @@ -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..notifications..timeout` [configuration key](configuration.md#configuration-files): diff --git a/docs/api/event_reference/other_events.md b/docs/api/event_reference/other_events.md index c8d07ffcc0..b9f054ddd0 100644 --- a/docs/api/event_reference/other_events.md +++ b/docs/api/event_reference/other_events.md @@ -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 @@ -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`
`Notification|null $notification`| -|`CreateNotificationEvent`|`NotificationService::createNotification`|`Notification $notification`
`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`
`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`
`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 diff --git a/docs/search/criteria_reference/notification_datecreated_criterion.md b/docs/search/criteria_reference/notification_datecreated_criterion.md new file mode 100644 index 0000000000..a984edcbd5 --- /dev/null +++ b/docs/search/criteria_reference/notification_datecreated_criterion.md @@ -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') =]] +``` diff --git a/docs/search/criteria_reference/notification_search_criteria.md b/docs/search/criteria_reference/notification_search_criteria.md new file mode 100644 index 0000000000..0dc037bb51 --- /dev/null +++ b/docs/search/criteria_reference/notification_search_criteria.md @@ -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| diff --git a/docs/search/criteria_reference/notification_status_criterion.md b/docs/search/criteria_reference/notification_status_criterion.md new file mode 100644 index 0000000000..fa49e3024e --- /dev/null +++ b/docs/search/criteria_reference/notification_status_criterion.md @@ -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') =]] +``` diff --git a/docs/search/criteria_reference/notification_type_criterion.md b/docs/search/criteria_reference/notification_type_criterion.md new file mode 100644 index 0000000000..7c10ed357c --- /dev/null +++ b/docs/search/criteria_reference/notification_type_criterion.md @@ -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') =]] +``` diff --git a/docs/templating/twig_function_reference/icon_twig_functions.md b/docs/templating/twig_function_reference/icon_twig_functions.md index a503f46d0b..f780c74129 100644 --- a/docs/templating/twig_function_reference/icon_twig_functions.md +++ b/docs/templating/twig_function_reference/icon_twig_functions.md @@ -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 @@ -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` | @@ -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` | diff --git a/docs/templating/twig_function_reference/img/icons/expand-right.png b/docs/templating/twig_function_reference/img/icons/expand-right.png new file mode 100644 index 0000000000..9939b01451 Binary files /dev/null and b/docs/templating/twig_function_reference/img/icons/expand-right.png differ diff --git a/docs/templating/twig_function_reference/img/icons/mail-open.png b/docs/templating/twig_function_reference/img/icons/mail-open.png new file mode 100644 index 0000000000..450518b0e8 Binary files /dev/null and b/docs/templating/twig_function_reference/img/icons/mail-open.png differ diff --git a/docs/templating/twig_function_reference/img/icons/mail.svg.png b/docs/templating/twig_function_reference/img/icons/mail.svg.png index 68d4f263a0..562e9ef34c 100644 Binary files a/docs/templating/twig_function_reference/img/icons/mail.svg.png and b/docs/templating/twig_function_reference/img/icons/mail.svg.png differ diff --git a/mkdocs.yml b/mkdocs.yml index ad58dad3c8..0829924de2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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