CoolCMS API

CommentThread extends BaseComponent
in package
uses InitializationTrait, FormTrait

Generic comment thread component for any commentable content (articles, events, news, ...).

Table of Contents

Constants

MODAL_TARGET  : mixed = 'commentThreadReply'

Properties

$commentPage  : int
Page of top-level comments (only thread types with a per-page setting, see `ThreadType::commentPerPageSetting()`).
$container  : Container
$routerDispatcher  : RouterDispatcher
$threadId  : int
$translator  : ITranslator
$appContext  : AppContext
$componentParameters  : array<string, mixed>
$currencyContext  : CurrencyContext|null
$deviceDetector  : DeviceDetector|null
$languageContext  : LanguageContext|null
$localizationContext  : LocalizationContext|null
$settingContext  : SettingContext
$themeContext  : ThemeContext|null
$translatorDomain  : string|null
$commentManager  : CommentManager
$commentThreadManager  : CommentThreadManager
$eventDispatcher  : EventDispatcher
$loginRequired  : bool|null
Memo of {@see isLoginRequired()} for the current request.
$modalRegistry  : ModalRegistry
$replyTo  : int|null
$threadType  : ThreadType|null|false
Memo of the thread type (false = not loaded yet).
$userManager  : UserManager

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
commentsPerPage()  : int
Top-level comments per page; 0 = no paging (the module has no such setting).
createComponent()  : IComponent|null
createComponentReplyForm()  : Form
Reply form (in the modal).
getAppContext()  : AppContext
getComponentParameter()  : mixed
Returns a component parameter, or null when it is not set.
getContainer()  : Container
getCurrencyContext()  : CurrencyContext|null
getLanguageContext()  : LanguageContext|null
getLocalizationContext()  : LocalizationContext|null
getReplyTo()  : int|null
Returns `replyTo` (used by `FormTrait`).
getRouterDispatcher()  : RouterDispatcher
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getThemeContext()  : ThemeContext|null
handleCommentPage()  : void
AJAX paging of top-level comments.
handleShowReplyForm()  : void
Signal that shows the reply form in a modal.
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
initializeAllContexts()  : void
injectDeviceDetector()  : void
isLoginRequired()  : bool
Returns whether the current visitor is a guest and the thread type allows comments only to logged-in users (`ThreadType::commentLoginSetting()`, e.g. Discussion `comment.onlyForLoggedIn`).
onCreate()  : void
onFormError()  : void
Validation errors: the modal is filled from the registry, so its content is rebuilt with the errors (the template lists `$form->errors`, field errors included). Without it an AJAX submit with an empty name or text ended with no response at all.
onSubmit()  : void
Form submit handler.
render()  : void
setAppContext()  : $this
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setLanguageContext()  : $this
setLocalizationContext()  : $this
setSettingContext()  : $this
setThemeContext()  : $this
setup()  : void
setupAppContext()  : void
typedComponent()  : T
Returns a subcomponent with a verified type.
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getModalTarget()  : string
Returns `MODAL_TARGET` (used by `FormTrait`).
getTranslator()  : ITranslator
setTemplateFile()  : void
setTranslator()  : self
createModalContent()  : string
Builds the modal HTML content (the form).
createModalEvent()  : ModalWindowEvent
Creates a `ModalWindowEvent` with the given options.
createMultiplierComponent()  : Multiplier<string|int, IComponent>
Creates a multiplier for the component.
createNewComponentInstance()  : IComponent|null
Creates a new component instance without adding it to the presenter; used by the multiplier.
createStandardComponent()  : IComponent|null
Creates a standard component (not a multiplier).
createSuccessContent()  : string
Builds the content shown after a successful submit.
handleSubmitError()  : void
Handles a submit error.
handleSubmitSuccess()  : void
Handles a successful submit.
initializeRender()  : void
Loads comments from the database and prepares them for the template.
initializeUsers()  : void
Loads avatars of the users who contributed to the discussion.
sortMessageList()  : void
Sorts comments by parent id for tree display.
threadType()  : ThreadType|null
Type of the current thread, loaded once per request.
updateModalContent()  : void
Updates the modal content.

Constants

MODAL_TARGET

private mixed MODAL_TARGET = 'commentThreadReply'

Properties

$commentPage

Page of top-level comments (only thread types with a per-page setting, see `ThreadType::commentPerPageSetting()`).

public int $commentPage = 1
Attributes
#[Persistent]

$componentParameters

protected array<string, mixed> $componentParameters = []

component parameters set by setComponentParameter()

$translatorDomain

protected string|null $translatorDomain = 'front.base.components.commentThread'

$loginRequired

Memo of {@see isLoginRequired()} for the current request.

private bool|null $loginRequired = null

$threadType

Memo of the thread type (false = not loaded yet).

private ThreadType|null|false $threadType = false

Methods

__call()

Dispatches `renderXyz()` to `render('Xyz', ...$args)`.

public __call(string $name, array<string|int, mixed> $args) : mixed

Called only when the component has no renderXyz() method of its own.

Parameters
$name : string
$args : array<string|int, mixed>

commentsPerPage()

Top-level comments per page; 0 = no paging (the module has no such setting).

public commentsPerPage() : int
Return values
int

createComponent()

public createComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

createComponentReplyForm()

Reply form (in the modal).

public createComponentReplyForm() : Form
Return values
Form

getComponentParameter()

Returns a component parameter, or null when it is not set.

public getComponentParameter(string $name) : mixed
Parameters
$name : string

getContainer()

public getContainer() : Container
Return values
Container

getReplyTo()

Returns `replyTo` (used by `FormTrait`).

public getReplyTo() : int|null
Return values
int|null

getSettings()

public getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

handleCommentPage()

AJAX paging of top-level comments.

public handleCommentPage([int $commentPage = 1 ]) : void
Parameters
$commentPage : int = 1

handleShowReplyForm()

Signal that shows the reply form in a modal.

public handleShowReplyForm([int|null $threadId = null ][, int|null $parentId = null ]) : void
Parameters
$threadId : int|null = null
$parentId : int|null = null

hasServiceByType()

Returns whether the container has a service of the given type.

public hasServiceByType(string $className) : bool

The name is composed dynamically (module plus component), so class_exists() runs first, and a true result guarantees a valid type.

Parameters
$className : string
Tags
phpstan-assert-if-true

class-string $className

Return values
bool

isLoginRequired()

Returns whether the current visitor is a guest and the thread type allows comments only to logged-in users (`ThreadType::commentLoginSetting()`, e.g. Discussion `comment.onlyForLoggedIn`).

public isLoginRequired() : bool

The front only hides the buttons and the form; the gate that holds is the Api CommentManager::beforeSave().

Return values
bool

onFormError()

Validation errors: the modal is filled from the registry, so its content is rebuilt with the errors (the template lists `$form->errors`, field errors included). Without it an AJAX submit with an empty name or text ended with no response at all.

public onFormError(Form $form) : void
Parameters
$form : Form

onSubmit()

Form submit handler.

public onSubmit(Form $form, ArrayHash $values) : void
Parameters
$form : Form
$values : ArrayHash

render()

public render([int|null $threadId = null ]) : void
Parameters
$threadId : int|null = null

setComponentParameter()

Sets a component parameter.

public setComponentParameter(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

typedComponent()

Returns a subcomponent with a verified type.

public typedComponent(string $name, T> $type) : T

Use it instead of an inline @var above $this['x'] (which does not narrow the type) and instead of the generic IComponent that $this['x'] returns. See Form::typedComponent().

Parameters
$name : string
$type : T>
Tags
template
Return values
T

frontPresenter()

Returns the front presenter the component is attached to (null outside the front end or when detached).

protected frontPresenter() : BasePresenter|null
Return values
BasePresenter|null

getModalTarget()

Returns `MODAL_TARGET` (used by `FormTrait`).

protected getModalTarget() : string
Return values
string

getTranslator()

protected getTranslator() : ITranslator
Return values
ITranslator

setTemplateFile()

protected setTemplateFile(string $dir, string $filename) : void
Parameters
$dir : string
$filename : string

setTranslator()

protected setTranslator(ITranslator $translator) : self
Parameters
$translator : ITranslator
Return values
self

createModalContent()

Builds the modal HTML content (the form).

private createModalContent() : string
Return values
string

createModalEvent()

Creates a `ModalWindowEvent` with the given options.

private createModalEvent(string $content[, array<string, mixed> $extraOptions = [] ]) : ModalWindowEvent
Parameters
$content : string
$extraOptions : array<string, mixed> = []
Return values
ModalWindowEvent

createMultiplierComponent()

Creates a multiplier for the component.

private createMultiplierComponent(string $name) : Multiplier<string|int, IComponent>
Parameters
$name : string
Return values
Multiplier<string|int, IComponent>

createNewComponentInstance()

Creates a new component instance without adding it to the presenter; used by the multiplier.

private createNewComponentInstance(string $baseName[, int|string|null $uniqueKey = null ]) : IComponent|null
Parameters
$baseName : string
$uniqueKey : int|string|null = null
Return values
IComponent|null

createStandardComponent()

Creates a standard component (not a multiplier).

private createStandardComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

createSuccessContent()

Builds the content shown after a successful submit.

private createSuccessContent() : string
Return values
string

handleSubmitError()

Handles a submit error.

private handleSubmitError(Form $form, string $transDomain[, Result|null $result = null ]) : void
Parameters
$form : Form
$transDomain : string
$result : Result|null = null

handleSubmitSuccess()

Handles a successful submit.

private handleSubmitSuccess(Form $form) : void
Parameters
$form : Form

initializeRender()

Loads comments from the database and prepares them for the template.

private initializeRender() : void

initializeUsers()

Loads avatars of the users who contributed to the discussion.

private initializeUsers(iterable<string|int, Comment> $messageList) : void
Parameters
$messageList : iterable<string|int, Comment>

sortMessageList()

Sorts comments by parent id for tree display.

private sortMessageList(iterable<string|int, Comment> $messageList) : void
Parameters
$messageList : iterable<string|int, Comment>

updateModalContent()

Updates the modal content.

private updateModalContent(string $content) : void
Parameters
$content : string
On this page

Search results