CoolCMS API

FormTrait

Grid form: one POST form wrapping the table.

  • The search fields of the second header row are built from the column filter definitions (controls filter__<column>, ranges filter__<column>__from/__to). A column name must go through FormTrait::getFilterControlName(), because Nette does not allow dotted paths (status.id) in a component name.
  • The search submit stores the values in the persistent state and redirects (post-redirect-get).
  • The group__<name> submits process the records ticked by checkboxes. The ids[] checkboxes are plain HTML inputs in the row template read via getHttpData(), so the form does not depend on the loaded data.

Texts are translated explicitly by the component translator; the form has no translator of its own, and select options arrive from the presenter already translated.

Table of Contents

Properties

$filterControlNames  : array<string, string>|null
Column => name of its filter control; computed lazily once.

Methods

getFilterControlName()  : string
Returns the form control name of the filter of the given column.
createComponentGridForm()  : Form
addFilterControls()  : void
deleteTreeNodes()  : Result
Deletes nodes of a tree grid in bulk; each node is deleted with its subtree ({@see \App\Core\Traits\Api\Models\Services\TreeTrait::deleteTreeNode()}).
filterControlNames()  : array<string, string>
flashTranslated()  : void
Flashes a message by key; the admin layout translates `{_'//' . $flash->message}`, so the full path including the component domain is needed.
processGroupAction()  : void
Handles a group action submit: passes the checkbox ids to the action callback; `delete` without a callback deletes through the manager.
processSearch()  : void
Handles the search submit: stores field values in the persistent state and redirects.
slugifyColumnName()  : string
stateToString()  : string
Converts a persistent state value (mixed, from the URL) to a string for form defaults.
t()  : string
Translates a key in the component domain.

Properties

$filterControlNames

Column => name of its filter control; computed lazily once.

private array<string, string>|null $filterControlNames = null

Methods

getFilterControlName()

Returns the form control name of the filter of the given column.

public getFilterControlName(string $column) : string

Nette allows only [a-zA-Z0-9_] in a component name while a column can be a dotted relation path (status.id), so other characters are replaced by an underscore. A collision after the conversion (status.id vs status_id) is resolved by a numeric suffix, which keeps the name unique within the grid.

Parameters
$column : string
Return values
string

createComponentGridForm()

protected createComponentGridForm() : Form
Return values
Form

addFilterControls()

private addFilterControls(Form $form, string $name, ColumnFilter $filter) : void
Parameters
$form : Form
$name : string
$filter : ColumnFilter

deleteTreeNodes()

Deletes nodes of a tree grid in bulk; each node is deleted with its subtree ({@see \App\Core\Traits\Api\Models\Services\TreeTrait::deleteTreeNode()}).

private deleteTreeNodes(array<string|int, int> $ids) : Result

An id that vanished meanwhile (a descendant of an already deleted node) is skipped.

Parameters
$ids : array<string|int, int>
Return values
Result

filterControlNames()

private filterControlNames() : array<string, string>
Return values
array<string, string> —

column => control name

flashTranslated()

Flashes a message by key; the admin layout translates `{_'//' . $flash->message}`, so the full path including the component domain is needed.

private flashTranslated(string $key, string $type) : void
Parameters
$key : string
$type : string

processGroupAction()

Handles a group action submit: passes the checkbox ids to the action callback; `delete` without a callback deletes through the manager.

private processGroupAction(GroupAction $action, Form $form) : void
Parameters
$action : GroupAction
$form : Form

processSearch()

Handles the search submit: stores field values in the persistent state and redirects.

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

slugifyColumnName()

private slugifyColumnName(string $column) : string
Parameters
$column : string
Return values
string

stateToString()

Converts a persistent state value (mixed, from the URL) to a string for form defaults.

private stateToString(mixed $value) : string
Parameters
$value : mixed
Return values
string

t()

Translates a key in the component domain.

private t(string $key) : string
Parameters
$key : string
Return values
string
On this page

Search results