CoolCMS API

InactiveRecordsReadFilterTrait

Limits reads by an unprivileged caller to live records: no inactive or deleted records and no internal fields.

Public get/getAll/getBy (granted to guest and registrated) would otherwise return drafts, including their texts and the editor's internal note. The front end does not render them anyway (it checks active/deleted itself), so the filter only prevents unpublished content from being pulled through the API.

A privileged caller (admin) gets the payload unchanged because admin lists need inactive records. Privilege is decided by PermissionResolver::isGrantedByPrivilegedRole() on the key of the evaluated action, the same method as in UserPresenter::filterReadPayload().

Runs in the BasePresenter::filterReadPayload() hook, after the query cache: the result depends on the caller, not on the query.

The presenter declares what is live through the methods below and calls self::filterInactiveRecords() from filterReadPayload().

Table of Contents

Methods

inactiveFilterDependentClasses()  : array<string, string>
Dependent classes (typically translations) mapped to the name of their parent pointer.
inactiveFilterEntityClass()  : string
Class of the main entity in `_references` (the presenter's Api entity).
inactiveFilterHiddenFields()  : array<int, string>
Fields an unprivileged caller does not receive even for a live record.
isLiveRecord()  : bool
Tells whether the record is live; by default `active` is true and `deleted` is false (a missing field does not restrict).
filterInactiveRecords()  : array<string, mixed>
pointerId()  : int|string|null
Returns the id from a `{id: N}` or `{id: {id: N}}` pointer (reference in `_references` / `items`), or null for any other shape.

Methods

inactiveFilterDependentClasses()

Dependent classes (typically translations) mapped to the name of their parent pointer.

protected inactiveFilterDependentClasses() : array<string, string>

Their rows are removed together with a hidden parent, otherwise the draft text would stay in _references.

Return values
array<string, string> —

class => field holding the {id: {id: N}} pointer

inactiveFilterEntityClass()

Class of the main entity in `_references` (the presenter's Api entity).

protected abstract inactiveFilterEntityClass() : string
Return values
string

inactiveFilterHiddenFields()

Fields an unprivileged caller does not receive even for a live record.

protected abstract inactiveFilterHiddenFields() : array<int, string>
Return values
array<int, string>

isLiveRecord()

Tells whether the record is live; by default `active` is true and `deleted` is false (a missing field does not restrict).

protected isLiveRecord(array<string|int, mixed> $row) : bool
Parameters
$row : array<string|int, mixed>
Return values
bool

filterInactiveRecords()

private filterInactiveRecords(array<string, mixed> $payload, string $action) : array<string, mixed>
Parameters
$payload : array<string, mixed>
$action : string
Return values
array<string, mixed>

pointerId()

Returns the id from a `{id: N}` or `{id: {id: N}}` pointer (reference in `_references` / `items`), or null for any other shape.

private static pointerId(mixed $pointer) : int|string|null
Parameters
$pointer : mixed
Return values
int|string|null
On this page

Search results