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]
$container
public
Container
$container
Attributes
- #[Inject]
$routerDispatcher
public
RouterDispatcher
$routerDispatcher
$threadId
public
int
$threadId
= 0
Attributes
- #[Persistent]
$translator
public
ITranslator
$translator
Tags
$appContext
protected
AppContext
$appContext
$componentParameters
protected
array<string, mixed>
$componentParameters
= []
component parameters set by setComponentParameter()
$currencyContext
protected
CurrencyContext|null
$currencyContext
= NULL
$deviceDetector
protected
DeviceDetector|null
$deviceDetector
= NULL
$languageContext
protected
LanguageContext|null
$languageContext
= NULL
$localizationContext
protected
LocalizationContext|null
$localizationContext
= NULL
$settingContext
protected
SettingContext
$settingContext
$themeContext
protected
ThemeContext|null
$themeContext
= NULL
$translatorDomain
protected
string|null
$translatorDomain
= 'front.base.components.commentThread'
$commentManager read-only
private
CommentManager
$commentManager
$commentThreadManager read-only
private
CommentThreadManager
$commentThreadManager
$eventDispatcher read-only
private
EventDispatcher
$eventDispatcher
$loginRequired
Memo of {@see isLoginRequired()} for the current request.
private
bool|null
$loginRequired
= null
$modalRegistry read-only
private
ModalRegistry
$modalRegistry
$replyTo
private
int|null
$replyTo
= null
$threadType
Memo of the thread type (false = not loaded yet).
private
ThreadType|null|false
$threadType
= false
$userManager read-only
private
UserManager
$userManager
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>
__construct()
public
__construct(CommentManager $commentManager, CommentThreadManager $commentThreadManager, UserManager $userManager, ModalRegistry $modalRegistry, EventDispatcher $eventDispatcher) : mixed
Parameters
- $commentManager : CommentManager
- $commentThreadManager : CommentThreadManager
- $userManager : UserManager
- $modalRegistry : ModalRegistry
- $eventDispatcher : EventDispatcher
commentsPerPage()
Top-level comments per page; 0 = no paging (the module has no such setting).
public
commentsPerPage() : int
Return values
intcreateComponent()
public
createComponent(string $name) : IComponent|null
Parameters
- $name : string
Return values
IComponent|nullcreateComponentReplyForm()
Reply form (in the modal).
public
createComponentReplyForm() : Form
Return values
FormgetAppContext()
public
getAppContext() : AppContext
Return values
AppContextgetComponentParameter()
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
ContainergetCurrencyContext()
public
getCurrencyContext() : CurrencyContext|null
Return values
CurrencyContext|nullgetLanguageContext()
public
getLanguageContext() : LanguageContext|null
Return values
LanguageContext|nullgetLocalizationContext()
public
getLocalizationContext() : LocalizationContext|null
Return values
LocalizationContext|nullgetReplyTo()
Returns `replyTo` (used by `FormTrait`).
public
getReplyTo() : int|null
Return values
int|nullgetRouterDispatcher()
public
getRouterDispatcher() : RouterDispatcher
Return values
RouterDispatchergetSettingContext()
public
getSettingContext() : SettingContext
Return values
SettingContextgetSettings()
public
getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>getThemeContext()
public
getThemeContext() : ThemeContext|null
Return values
ThemeContext|nullhandleCommentPage()
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
Return values
boolinitializeAllContexts()
public
initializeAllContexts() : void
injectDeviceDetector()
public
injectDeviceDetector(DeviceDetector $detector) : void
Parameters
- $detector : DeviceDetector
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
boolonCreate()
public
onCreate() : void
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
setAppContext()
public
setAppContext(AppContext $appContext) : $this
Parameters
- $appContext : AppContext
Return values
$thissetComponentParameter()
Sets a component parameter.
public
setComponentParameter(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
setCurrencyContext()
public
setCurrencyContext(CurrencyContext|null $currencyContext) : $this
Parameters
- $currencyContext : CurrencyContext|null
Return values
$thissetLanguageContext()
public
setLanguageContext(LanguageContext|null $languageContext) : $this
Parameters
- $languageContext : LanguageContext|null
Return values
$thissetLocalizationContext()
public
setLocalizationContext(LocalizationContext|null $localizationContext) : $this
Parameters
- $localizationContext : LocalizationContext|null
Return values
$thissetSettingContext()
public
setSettingContext(SettingContext $settingContext) : $this
Parameters
- $settingContext : SettingContext
Return values
$thissetThemeContext()
public
setThemeContext(ThemeContext|null $themeContext) : $this
Parameters
- $themeContext : ThemeContext|null
Return values
$thissetup()
public
setup(BasePresenter|BasePresenter $presenter) : void
Parameters
- $presenter : BasePresenter|BasePresenter
setupAppContext()
public
setupAppContext(AppContext $appContext) : void
Parameters
- $appContext : AppContext
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
Return values
TfrontPresenter()
Returns the front presenter the component is attached to (null outside the front end or when detached).
protected
frontPresenter() : BasePresenter|null
Return values
BasePresenter|nullgetModalTarget()
Returns `MODAL_TARGET` (used by `FormTrait`).
protected
getModalTarget() : string
Return values
stringgetTranslator()
protected
getTranslator() : ITranslator
Return values
ITranslatorsetTemplateFile()
protected
setTemplateFile(string $dir, string $filename) : void
Parameters
- $dir : string
- $filename : string
setTranslator()
protected
setTranslator(ITranslator $translator) : self
Parameters
- $translator : ITranslator
Return values
selfcreateModalContent()
Builds the modal HTML content (the form).
private
createModalContent() : string
Return values
stringcreateModalEvent()
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
ModalWindowEventcreateMultiplierComponent()
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|nullcreateStandardComponent()
Creates a standard component (not a multiplier).
private
createStandardComponent(string $name) : IComponent|null
Parameters
- $name : string
Return values
IComponent|nullcreateSuccessContent()
Builds the content shown after a successful submit.
private
createSuccessContent() : string
Return values
stringhandleSubmitError()
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>
threadType()
Type of the current thread, loaded once per request.
private
threadType() : ThreadType|null
Return values
ThreadType|nullupdateModalContent()
Updates the modal content.
private
updateModalContent(string $content) : void
Parameters
- $content : string