Itemlist
in package
Used to generate HTML for a table of database records.
This is usually used for the admin/contents/* route which provides the main UI to operators for a given ManagedAdminController
Table of Contents
Properties
- $aggregate : array<string|int, mixed>
- $checkboxes : bool
- $items : array<string|int, mixed>|iterable<string|int, mixed>|PDOStatement
- $main_columns : array<string, string|ColModifier, 1: string}>
- $ordering : bool
- $table_class : string
- $actions : array<string|int, mixed>
- $actions_classes : string
- $actions_func : callable|null
- $row_classes_func : callable|null
Methods
- __toString() : mixed
- addAction() : void
- Adds an action to this itemlist.
- addAggregateColumn() : void
- Add an aggregate which operates on the values of a column
- addAggregateValue() : void
- Add an aggregate which is just a single pre-computed value
- removeAction() : void
- Remove an action from this itemlist
- render() : string
- setActionsClasses() : void
- Set link classes common for all actions The default is "actions--link".
- setActionsFunc() : void
- Set a function which should return content for the actions column The func should have this signature:
- setCheckboxes() : void
- Does this itemlist support checkboxes?
- setOrdering() : void
- Does this itemlist support ordering?
- setRowClassesFunc() : void
- Set a function which should return the classes to use on the row.
- calculateAggregateColumn() : int|float
- Calculate the result of an aggregation
- renderItem() : string
- Renders an itemlist definition
- urlReplace() : string
- Does the parameter replacements on an action url
Properties
$aggregate
public
array<string|int, mixed>
$aggregate
= []
$checkboxes
public
bool
$checkboxes
$items
public
array<string|int, mixed>|iterable<string|int, mixed>|PDOStatement
$items
$main_columns
public
array<string, string|ColModifier, 1: string}>
$main_columns
$ordering
public
bool
$ordering
$table_class
public
string
$table_class
= 'main-list'
$actions
private
array<string|int, mixed>
$actions
= array()
$actions_classes
private
string
$actions_classes
= 'actions--link'
$actions_func
private
callable|null
$actions_func
= null
$row_classes_func
private
callable|null
$row_classes_func
= null
Methods
__toString()
public
__toString() : mixed
addAction()
Adds an action to this itemlist.
public
addAction(string $name, string $url[, string $classes = '' ][, callable $show_func = null ]) : void
The special action 'edit' is used when the row is clicked.
Parameters
- $name : string
-
Link label
- $url : string
-
Link URL. This URL is processed by Itemlist::urlReplace during rendering
- $classes : string = ''
-
Additional classes for the A element
- $show_func : callable = null
-
Function called for each row to show or hide this action for that row
addAggregateColumn()
Add an aggregate which operates on the values of a column
public
addAggregateColumn(string $title, string $operation[, ColModifier|null $modifier = null ]) : void
Parameters
- $title : string
-
Column to aggregate values of
- $operation : string
-
Aggregation operation, 'sum', 'count', 'avg'
- $modifier : ColModifier|null = null
-
Column modifier applied after aggregation to format the result
Tags
addAggregateValue()
Add an aggregate which is just a single pre-computed value
public
addAggregateValue(string $title, string $value) : void
Parameters
- $title : string
-
Column to aggregate values of
- $value : string
-
Value to output for this column; this will be HTML-encoded on output
removeAction()
Remove an action from this itemlist
public
removeAction(string $name) : void
Parameters
- $name : string
render()
public
render() : string
Return values
stringsetActionsClasses()
Set link classes common for all actions The default is "actions--link".
public
setActionsClasses(string $classes) : void
Parameters
- $classes : string
-
Classes for the A element
Tags
setActionsFunc()
Set a function which should return content for the actions column The func should have this signature:
public
setActionsFunc(callable $func) : void
string function mycallable(array $row)
The return value should be HTML with the links
Parameters
- $func : callable
-
returns string of HTML
setCheckboxes()
Does this itemlist support checkboxes?
public
setCheckboxes(bool $checkboxes) : void
Parameters
- $checkboxes : bool
setOrdering()
Does this itemlist support ordering?
public
setOrdering(bool $ordering) : void
Parameters
- $ordering : bool
setRowClassesFunc()
Set a function which should return the classes to use on the row.
public
setRowClassesFunc(callable $func) : void
string function mycallable(array $row)
The return value should be a string of class names
Parameters
- $func : callable
Tags
calculateAggregateColumn()
Calculate the result of an aggregation
protected
static calculateAggregateColumn(string $operation, array<string|int, mixed> $values) : int|float
Parameters
- $operation : string
-
Aggregation operation, 'sum', 'count', 'avg'
- $values : array<string|int, mixed>
-
Raw values, direct from the database
Return values
int|float —Aggregation result
renderItem()
Renders an itemlist definition
protected
static renderItem(mixed $defn, array<string|int, mixed>|object $item_data) : string
Definition can be one of:
- A field name
- An array with two indexes, 0 => ColModifier, 1 => field name
- A Closure, which will receive one argument of the entire row as an array, and must return a string of HTML
The Closure result supports a subset of HTML, Text::limitedSubsetHtml for more details
Parameters
- $defn : mixed
- $item_data : array<string|int, mixed>|object
-
Result row
Return values
stringurlReplace()
Does the parameter replacements on an action url
private
urlReplace(string $url, array<string|int, mixed> $item) : string
Replaces %% with the id of the record.
Parameters
- $url : string
- $item : array<string|int, mixed>