NotificationTargetResolver
in package
Resolves where a notification leads: maps a notification type (`cms_system_notification_types`) to the admin edit destination of the record the notification is about.
A notification carries the id of a foreign record in its id column
(Notification::$itemId), not its own notification_id.
The type says which table the record is from, so "new registration" + id = 5 means
user 5, not notification 5. The link is always destination + ['id' => itemId].
The target is data, not a constant in code: the type points through
cms_admin_system_pages_page_id to a row of the admin page code list, which yields
presenter:action. A type added in the admin gets a link without a code change.
IMPORTANT: because the destination comes from data, the target presenter is checked for
existence (presenterExists()); otherwise link() in the admin header would break
every page. A missing or empty target yields null and the caller handles the fallback.
Shared by the header bell and the notification list, hence a separate service.
The type cache is an instance property, not static, because the service lives for
one request (OwnershipOverrideChecker).
Table of Contents
Properties
- $adminPageManager : AdminPageManager
- $destinations : array<int, string>|null
- $notificationTypeManager : NotificationTypeManager
-
$types
: array<int, array{key: string, pageId: int|null, icon: string|null, names: array
}>|null
Methods
- __construct() : mixed
- destinationForType() : string|null
- Returns the edit destination of the record the notification is about; `null` when the type has no target (no page assigned, no type, or the target presenter does not exist).
- iconForType() : string|null
- Returns the Font Awesome icon class of the type; `null` when the type has no icon (the caller supplies a placeholder) or does not exist.
- keyForType() : string|null
- Returns the type key (e.g. `ORDER_NEW`); `null` when the type does not exist.
- nameForType() : string
- Returns the type name in the given language (fallback: first non-empty translation, then the key). An empty string means the type does not exist.
- typeOptions() : array<int, string>
- Returns `id => name` options for a grid select/filter in the given language, sorted alphabetically.
- getDestinations() : array<int, string>
- Returns `page_id => ':Presenter:action'` for the pages the types point to, with one query limited to the ids actually used.
-
getTypes()
: array<int, array{key: string, pageId: int|null, icon: string|null, names: array
}> - presenterExists() : bool
- Tells whether the page's presenter exists in this build.
Properties
$adminPageManager read-only
private
AdminPageManager
$adminPageManager
$destinations
private
array<int, string>|null
$destinations
= null
page_id => :Presenter:action, only for pages the types point to
$notificationTypeManager read-only
private
NotificationTypeManager
$notificationTypeManager
$types
private
array<int, array{key: string, pageId: int|null, icon: string|null, names: array}>|null
$types
= null
type code list, loaded at most once per request
Methods
__construct()
public
__construct(NotificationTypeManager $notificationTypeManager, AdminPageManager $adminPageManager) : mixed
Parameters
- $notificationTypeManager : NotificationTypeManager
- $adminPageManager : AdminPageManager
destinationForType()
Returns the edit destination of the record the notification is about; `null` when the type has no target (no page assigned, no type, or the target presenter does not exist).
public
destinationForType(int|null $typeId) : string|null
Parameters
- $typeId : int|null
Return values
string|nulliconForType()
Returns the Font Awesome icon class of the type; `null` when the type has no icon (the caller supplies a placeholder) or does not exist.
public
iconForType(int|null $typeId) : string|null
Parameters
- $typeId : int|null
Return values
string|nullkeyForType()
Returns the type key (e.g. `ORDER_NEW`); `null` when the type does not exist.
public
keyForType(int|null $typeId) : string|null
Parameters
- $typeId : int|null
Return values
string|nullnameForType()
Returns the type name in the given language (fallback: first non-empty translation, then the key). An empty string means the type does not exist.
public
nameForType(int|null $typeId, int|null $langId) : string
Parameters
- $typeId : int|null
- $langId : int|null
Return values
stringtypeOptions()
Returns `id => name` options for a grid select/filter in the given language, sorted alphabetically.
public
typeOptions(int|null $langId) : array<int, string>
Parameters
- $langId : int|null
Return values
array<int, string>getDestinations()
Returns `page_id => ':Presenter:action'` for the pages the types point to, with one query limited to the ids actually used.
private
getDestinations() : array<int, string>
Return values
array<int, string>getTypes()
private
getTypes() : array<int, array{key: string, pageId: int|null, icon: string|null, names: array}>
Return values
array<int, array{key: string, pageId: int|null, icon: string|null, names: arraypresenterExists()
Tells whether the page's presenter exists in this build.
private
presenterExists(string $presenter) : bool
The page code list lives in the DB, so it can outlive a deleted or renamed presenter.
Without this check link() throws, and because the bell sits in the layout, it would
break every admin page, not only notifications. Same reasoning as
Search::resolveLink().
Parameters
- $presenter : string