Documentation

ListController extends ControllerBehavior
in package

Adds features for working with backend lists.

This behavior is implemented in the controller like so:

public $implement = [
    'Backend.Behaviors.ListController',
];

public $listConfig = 'config_list.yaml';

The $listConfig property makes reference to the list configuration values as either a YAML file, located in the controller view directory, or directly as a PHP array.

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

$assetPath  : string
$extendableStaticCalledClass  : string
$layout  : string
$suppressLayout  : bool
$vars  : array<string|int, mixed>
$actions  : array<string|int, mixed>
$assets  : array<string|int, mixed>
$config  : array<string|int, mixed>
$configPath  : string
$controller  : Controller
$extensionCallbacks  : array<string|int, mixed>
$extensionHidden  : mixed
$filterWidgets  : array<string|int, WidgetBase>
$layoutPath  : string
$listConfig  : array<string|int, mixed>
$listDefinitions  : array<string|int, mixed>
$listWidgets  : array<string|int, WidgetBase>
$primaryDefinition  : string
$requiredConfig  : array<string|int, mixed>
$requiredProperties  : array<string|int, mixed>
$toolbarWidgets  : array<string|int, WidgetBase>
$viewPath  : string|array<string|int, mixed>
__construct()  : mixed
Behavior constructor
addCss()  : void
Adds StyleSheet asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
addJs()  : void
Adds JavaScript asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
addRss()  : void
Adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
addViewPath()  : void
Prepends a path on the available view path locations.
combineAssets()  : string
Run the provided assets through the Asset Combiner
extend()  : mixed
extendListColumns()  : void
Static helper for extending list columns.
extendListFilterScopes()  : void
Static helper for extending filter scopes.
extensionApplyInitCallbacks()  : mixed
extensionExtendCallback()  : void
Helper method for `::extend()` static method
extensionIsHiddenField()  : mixed
extensionIsHiddenMethod()  : mixed
flushAssets()  : void
Disables the use, and subequent broadcast, of assets. This is useful to call during an AJAX request to speed things up. This method works by specifically targeting the hasAssetsDefined method.
getAssetPath()  : string
Locates a file based on it's definition. If the file starts with a forward slash, it will be returned in context of the application public path, otherwise it will be returned in context of the asset path.
getAssetPaths()  : array<string|int, mixed>
Returns an array of all registered asset paths.
getCalledExtensionClass()  : mixed
getConfig()  : string
Safe accessor for configuration values.
getConfigPath()  : string
Locates a file based on it's definition. If the file starts with the ~ symbol it will be returned in context of the application base path, otherwise it will be returned in context of the config path.
getViewPath()  : string
Locates a file based on its definition. The file name can be prefixed with a symbol (~|$) to return in context of the application or plugin base path, otherwise it will be returned in context of this object view path.
getViewPaths()  : array<string|int, mixed>
Returns the active view path locations.
guessConfigPath()  : string
Guess the package path for the called class.
guessConfigPathFrom()  : string
Guess the package path from a specified class.
guessViewPath()  : string
Guess the package path for the called class.
guessViewPathFrom()  : string
Guess the package path from a specified class.
hasAssetsDefined()  : bool
Returns true if assets any have been added.
index()  : void
Index Controller action.
index_onDelete()  : void
Bulk delete records.
listExtendColumns()  : void
Called after the list columns are defined.
listExtendModel()  : Model
Controller override: Extend supplied model
listExtendQuery()  : mixed
Controller override: Extend the query used for populating the list after the default query is processed.
listExtendQueryBefore()  : mixed
Controller override: Extend the query used for populating the list before the default query is processed.
listExtendRecords()  : mixed
Controller override: Extend the records used for populating the list after the query is processed.
listFilterExtendQuery()  : mixed
Controller override: Extend the query used for populating the filter options before the default query is processed.
listFilterExtendScopes()  : void
Called after the filter scopes are defined.
listGetConfig()  : WidgetBase
Returns the configuration used by this behavior.
listGetWidget()  : WidgetBase
Returns the widget used by this behavior.
listInjectRowClass()  : string|void
Returns a CSS class name for a list row (<tr class="...">).
listMakePartial()  : string
Controller accessor for making partials within this behavior.
listOverrideColumnValue()  : string|void
Replace a table column value (<td>...</td>)
listOverrideHeaderValue()  : string|void
Replace the entire table header contents (<th>...</th>) with custom HTML
listRefresh()  : array<string|int, mixed>
Refreshes the list container only, useful for returning in custom AJAX requests.
listRender()  : string
Renders the widget collection.
makeAssets()  : string
Outputs `<link>` and `<script>` tags to load assets previously added with addJs and addCss method calls
makeConfig()  : array<string|int, mixed>|stdClass
Reads the contents of the supplied file and applies it to this object.
makeConfigFromArray()  : stdClass
Makes a config object from an array, making the first level keys properties of a new object.
makeFileContents()  : string
Includes a file path using output buffering.
makeFormWidget()  : FormWidgetBase
Makes a form widget object with the supplied form field and widget configuration.
makeLayout()  : mixed
Render a layout.
makeLayoutPartial()  : string
Renders a layout partial
makeList()  : Lists
Prepare the widgets used by this action
makeLists()  : array<string|int, mixed>
Creates all the list widgets based on the definitions.
makePartial()  : mixed
Render a partial file contents located in the views folder.
makeView()  : string
Loads a view with the name specified. Applies layout if its name is provided by the parent object.
makeViewContent()  : string
Renders supplied contents inside a layout.
makeWidget()  : mixed|WidgetBase
Makes a widget object with the supplied configuration file.
mergeConfig()  : stdClass
Merges two configuration sources, either prepared or not, and returns them as a single configuration object.
resetSession()  : void
Resets all session data related to this widget.
setConfig()  : mixed
Sets the configuration values
addAsset()  : mixed
Adds the provided asset to the internal asset collections
controllerMethodExists()  : bool
Returns true in case if a specified method exists in the extended controller.
extensionHideField()  : mixed
extensionHideMethod()  : mixed
getAssetEntryBuildPath()  : string
Internal helper, attaches a build code to an asset path
getAssetScheme()  : string
Internal helper, get asset scheme
getLocalPath()  : mixed
getSession()  : string
Retrieves a widget related key/value pair from session data.
handleViewException()  : void
Handle a view exception.
hideAction()  : mixed
Protects a public method from being available as an controller action.
makeSessionId()  : string
Returns a unique session identifier for this widget and controller action.
putSession()  : void
Saves a widget related key/value pair in to session data.
removeDuplicates()  : void
Removes duplicate assets from the entire collection.

Properties

$assetPath

public string $assetPath

Specifies a path to the asset directory.

$extendableStaticCalledClass

public static string $extendableStaticCalledClass = null

The calling class when using a static method.

$layout

public string $layout

Layout to use for the view.

$suppressLayout

public bool $suppressLayout = false

Prevents the use of a layout.

$vars

public array<string|int, mixed> $vars = []

A list of variables to pass to the page.

$actions

protected array<string|int, mixed> $actions = ['index']

Visible actions in context of the controller

$assets

protected array<string|int, mixed> $assets = ['js' => [], 'css' => [], 'rss' => []]

Collection of assets to display in the layout.

$configPath

protected string $configPath

Specifies a path to the config directory.

$extensionCallbacks

protected static array<string|int, mixed> $extensionCallbacks = []

Used to extend the constructor of an extension class. Eg:

BehaviorClass::extend(function($obj) { })

$extensionHidden

protected mixed $extensionHidden = ['fields' => [], 'methods' => ['extensionIsHiddenField', 'extensionIsHiddenMethod']]

$filterWidgets

protected array<string|int, WidgetBase> $filterWidgets = []

Reference to the filter widget objects.

$layoutPath

protected string $layoutPath

Specifies a path to the layout directory.

$listConfig

protected array<string|int, mixed> $listConfig = []

List configuration, keys for alias and value for config objects.

$listDefinitions

protected array<string|int, mixed> $listDefinitions

List definitions, keys for alias and value for configuration.

$primaryDefinition

protected string $primaryDefinition

The primary list alias to use. Default: list

$requiredConfig

protected array<string|int, mixed> $requiredConfig = ['modelClass', 'list']

Configuration values that must exist when applying the primary config file.

  • modelClass: Class name for the model
  • list: List column definitions

$requiredProperties

protected array<string|int, mixed> $requiredProperties = ['listConfig']

Properties that must exist in the controller using this behavior.

Tags
inheritDoc

$toolbarWidgets

protected array<string|int, WidgetBase> $toolbarWidgets = []

Reference to the toolbar widget objects.

$viewPath

protected string|array<string|int, mixed> $viewPath

Specifies a path to the views directory.

Methods

addCss()

Adds StyleSheet asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

public addCss(string $name[, array<string|int, mixed> $attributes = [] ]) : void
Parameters
$name : string

Specifies a path (URL) to the script.

$attributes : array<string|int, mixed> = []

Adds extra HTML attributes to the asset link.

Return values
void

addJs()

Adds JavaScript asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

public addJs(string $name[, array<string|int, mixed> $attributes = [] ]) : void
Parameters
$name : string

Specifies a path (URL) to the script.

$attributes : array<string|int, mixed> = []

Adds extra HTML attributes to the asset link.

Return values
void

addRss()

Adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

public addRss(string $name[, array<string|int, mixed> $attributes = [] ]) : void
Parameters
$name : string

Specifies a path (URL) to the RSS channel

$attributes : array<string|int, mixed> = []

Adds extra HTML attributes to the asset link.

Return values
void

addViewPath()

Prepends a path on the available view path locations.

public addViewPath(string|array<string|int, mixed> $path) : void
Parameters
$path : string|array<string|int, mixed>
Return values
void

combineAssets()

Run the provided assets through the Asset Combiner

public combineAssets(array<string|int, mixed> $assets[, string $localPath = '' ]) : string
Parameters
$assets : array<string|int, mixed>

Collection of assets

$localPath : string = ''

Prefix all assets with this path (optional)

Return values
string

extend()

public static extend(callable $callback) : mixed
Parameters
$callback : callable
Return values
mixed

extendListColumns()

Static helper for extending list columns.

public static extendListColumns(callable $callback) : void
Parameters
$callback : callable
Return values
void

extendListFilterScopes()

Static helper for extending filter scopes.

public static extendListFilterScopes(callable $callback) : void
Parameters
$callback : callable
Return values
void

extensionApplyInitCallbacks()

public extensionApplyInitCallbacks() : mixed
Return values
mixed

extensionExtendCallback()

Helper method for `::extend()` static method

public static extensionExtendCallback(callable $callback) : void
Parameters
$callback : callable
Return values
void

extensionIsHiddenField()

public extensionIsHiddenField(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

extensionIsHiddenMethod()

public extensionIsHiddenMethod(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

flushAssets()

Disables the use, and subequent broadcast, of assets. This is useful to call during an AJAX request to speed things up. This method works by specifically targeting the hasAssetsDefined method.

public flushAssets() : void
Return values
void

getAssetPath()

Locates a file based on it's definition. If the file starts with a forward slash, it will be returned in context of the application public path, otherwise it will be returned in context of the asset path.

public getAssetPath(string $fileName[, string $assetPath = null ]) : string
Parameters
$fileName : string

File to load.

$assetPath : string = null

Explicitly define an asset path.

Return values
string

Relative path to the asset file.

getAssetPaths()

Returns an array of all registered asset paths.

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

getCalledExtensionClass()

public static getCalledExtensionClass() : mixed
Return values
mixed

getConfig()

Safe accessor for configuration values.

public getConfig([string $name = null ][, mixed $default = null ]) : string
Parameters
$name : string = null

Config name, supports array names like "field[key]"

$default : mixed = null

Default value if nothing is found

Return values
string

getConfigPath()

Locates a file based on it's definition. If the file starts with the ~ symbol it will be returned in context of the application base path, otherwise it will be returned in context of the config path.

public getConfigPath(string $fileName[, mixed $configPath = null ]) : string
Parameters
$fileName : string

File to load.

$configPath : mixed = null

Explicitly define a config path.

Return values
string

Full path to the config file.

getViewPath()

Locates a file based on its definition. The file name can be prefixed with a symbol (~|$) to return in context of the application or plugin base path, otherwise it will be returned in context of this object view path.

public getViewPath(string $fileName[, mixed $viewPath = null ]) : string
Parameters
$fileName : string

File to load.

$viewPath : mixed = null

Explicitly define a view path.

Return values
string

Full path to the view file.

getViewPaths()

Returns the active view path locations.

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

guessConfigPath()

Guess the package path for the called class.

public guessConfigPath([string $suffix = '' ]) : string
Parameters
$suffix : string = ''

An extra path to attach to the end

Return values
string

guessConfigPathFrom()

Guess the package path from a specified class.

public guessConfigPathFrom(string $class[, string $suffix = '' ]) : string
Parameters
$class : string

Class to guess path from.

$suffix : string = ''

An extra path to attach to the end

Return values
string

guessViewPath()

Guess the package path for the called class.

public guessViewPath([string $suffix = '' ][, bool $isPublic = false ]) : string
Parameters
$suffix : string = ''

An extra path to attach to the end

$isPublic : bool = false

Returns public path instead of an absolute one

Return values
string

guessViewPathFrom()

Guess the package path from a specified class.

public guessViewPathFrom(string $class[, string $suffix = '' ][, bool $isPublic = false ]) : string
Parameters
$class : string

Class to guess path from.

$suffix : string = ''

An extra path to attach to the end

$isPublic : bool = false

Returns public path instead of an absolute one

Return values
string

hasAssetsDefined()

Returns true if assets any have been added.

public hasAssetsDefined() : bool
Return values
bool

index()

Index Controller action.

public index() : void
Return values
void

index_onDelete()

Bulk delete records.

public index_onDelete() : void
Tags
throws
ApplicationException

when the parent definition is missing.

Return values
void

listExtendColumns()

Called after the list columns are defined.

public listExtendColumns(Lists $host) : void
Parameters
$host : Lists

The hosting list widget

Return values
void

listExtendModel()

Controller override: Extend supplied model

public listExtendModel(Model $model[, string|null $definition = null ]) : Model
Parameters
$model : Model
$definition : string|null = null
Return values
Model

listExtendQuery()

Controller override: Extend the query used for populating the list after the default query is processed.

public listExtendQuery(Builder $query[, string|null $definition = null ]) : mixed
Parameters
$query : Builder
$definition : string|null = null
Return values
mixed

listExtendQueryBefore()

Controller override: Extend the query used for populating the list before the default query is processed.

public listExtendQueryBefore(Builder $query[, string|null $definition = null ]) : mixed
Parameters
$query : Builder
$definition : string|null = null
Return values
mixed

listFilterExtendQuery()

Controller override: Extend the query used for populating the filter options before the default query is processed.

public listFilterExtendQuery(Builder $query, array<string|int, mixed> $scope) : mixed
Parameters
$query : Builder
$scope : array<string|int, mixed>
Return values
mixed

listFilterExtendScopes()

Called after the filter scopes are defined.

public listFilterExtendScopes(Filter $host) : void
Parameters
$host : Filter

The hosting filter widget

Return values
void

listGetConfig()

Returns the configuration used by this behavior.

public listGetConfig([mixed $definition = null ]) : WidgetBase
Parameters
$definition : mixed = null
Return values
WidgetBase

listGetWidget()

Returns the widget used by this behavior.

public listGetWidget([mixed $definition = null ]) : WidgetBase
Parameters
$definition : mixed = null
Return values
WidgetBase

listInjectRowClass()

Returns a CSS class name for a list row (<tr class="...">).

public listInjectRowClass(Model $record[, string|null $definition = null ]) : string|void
Parameters
$record : Model

The populated model used for the column

$definition : string|null = null

List definition (optional)

Return values
string|void

CSS class name

listMakePartial()

Controller accessor for making partials within this behavior.

public listMakePartial(string $partial[, array<string|int, mixed> $params = [] ]) : string
Parameters
$partial : string
$params : array<string|int, mixed> = []
Return values
string

Partial contents

listOverrideColumnValue()

Replace a table column value (<td>...</td>)

public listOverrideColumnValue(Model $record, string $columnName[, string|null $definition = null ]) : string|void
Parameters
$record : Model

The populated model used for the column

$columnName : string

The column name to override

$definition : string|null = null

List definition (optional)

Return values
string|void

HTML view

listOverrideHeaderValue()

Replace the entire table header contents (<th>...</th>) with custom HTML

public listOverrideHeaderValue(string $columnName[, string|null $definition = null ]) : string|void
Parameters
$columnName : string

The column name to override

$definition : string|null = null

List definition (optional)

Return values
string|void

HTML view

listRefresh()

Refreshes the list container only, useful for returning in custom AJAX requests.

public listRefresh([string $definition = null ]) : array<string|int, mixed>
Parameters
$definition : string = null

Optional list definition.

Return values
array<string|int, mixed>

The list element selector as the key, and the list contents are the value.

listRender()

Renders the widget collection.

public listRender([string $definition = null ]) : string
Parameters
$definition : string = null

Optional list definition.

Tags
throws
ApplicationException

when there are no list widgets set.

Return values
string

Rendered HTML for the list.

makeAssets()

Outputs `<link>` and `<script>` tags to load assets previously added with addJs and addCss method calls

public makeAssets([string $type = null ]) : string
Parameters
$type : string = null

Return an asset collection of a given type (css, rss, js) or null for all.

Return values
string

makeConfig()

Reads the contents of the supplied file and applies it to this object.

public makeConfig([array<string|int, mixed> $configFile = [] ][, array<string|int, mixed> $requiredConfig = [] ]) : array<string|int, mixed>|stdClass
Parameters
$configFile : array<string|int, mixed> = []
$requiredConfig : array<string|int, mixed> = []
Return values
array<string|int, mixed>|stdClass

makeConfigFromArray()

Makes a config object from an array, making the first level keys properties of a new object.

public makeConfigFromArray([array<string|int, mixed> $configArray = [] ]) : stdClass
Parameters
$configArray : array<string|int, mixed> = []

Config array.

Return values
stdClass

The config object

makeFileContents()

Includes a file path using output buffering.

public makeFileContents(string $filePath[, array<string|int, mixed> $extraParams = [] ]) : string

Ensures that vars are available.

Parameters
$filePath : string

Absolute path to the view file.

$extraParams : array<string|int, mixed> = []

Parameters that should be available to the view.

Return values
string

makeFormWidget()

Makes a form widget object with the supplied form field and widget configuration.

public makeFormWidget(string $class[, mixed $fieldConfig = [] ][, array<string|int, mixed> $widgetConfig = [] ]) : FormWidgetBase
Parameters
$class : string

Widget class name

$fieldConfig : mixed = []

A field name, an array of config or a FormField object.

$widgetConfig : array<string|int, mixed> = []

An array of config.

Return values
FormWidgetBase

The widget object

makeLayout()

Render a layout.

public makeLayout([string $name = null ][, array<string|int, mixed> $params = [] ][, bool $throwException = true ]) : mixed
Parameters
$name : string = null

Specifies the layout name. If this parameter is omitted, the $layout property will be used.

$params : array<string|int, mixed> = []

Parameter variables to pass to the view.

$throwException : bool = true

Throw an exception if the layout is not found

Return values
mixed

The layout contents, or false.

makeLayoutPartial()

Renders a layout partial

public makeLayoutPartial(string $partial[, array<string|int, mixed> $params = [] ]) : string
Parameters
$partial : string

The view to load.

$params : array<string|int, mixed> = []

Parameter variables to pass to the view.

Return values
string

The layout partial contents

makeList()

Prepare the widgets used by this action

public makeList([mixed $definition = null ]) : Lists
Parameters
$definition : mixed = null
Return values
Lists

makeLists()

Creates all the list widgets based on the definitions.

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

makePartial()

Render a partial file contents located in the views folder.

public makePartial(string $partial[, array<string|int, mixed> $params = [] ][, bool $throwException = true ]) : mixed
Parameters
$partial : string

The view to load.

$params : array<string|int, mixed> = []

Parameter variables to pass to the view.

$throwException : bool = true

Throw an exception if the partial is not found.

Return values
mixed

Partial contents or false if not throwing an exception.

makeView()

Loads a view with the name specified. Applies layout if its name is provided by the parent object.

public makeView(string $view) : string

The view file must be situated in the views directory, and has the extension "htm".

Parameters
$view : string

Specifies the view name, without extension. Eg: "index".

Return values
string

makeViewContent()

Renders supplied contents inside a layout.

public makeViewContent(string $contents[, string $layout = null ]) : string
Parameters
$contents : string

The inner contents as a string.

$layout : string = null

Specifies the layout name.

Return values
string

makeWidget()

Makes a widget object with the supplied configuration file.

public makeWidget(string $class[, array<string|int, mixed> $widgetConfig = [] ]) : mixed|WidgetBase
Parameters
$class : string

Widget class name

$widgetConfig : array<string|int, mixed> = []

An array of config.

Return values
mixed|WidgetBase

The widget object

mergeConfig()

Merges two configuration sources, either prepared or not, and returns them as a single configuration object.

public mergeConfig(mixed $configA, mixed $configB) : stdClass
Parameters
$configA : mixed
$configB : mixed
Return values
stdClass

The config object

resetSession()

Resets all session data related to this widget.

public resetSession() : void
Return values
void

setConfig()

Sets the configuration values

public setConfig(mixed $config[, array<string|int, mixed> $required = [] ]) : mixed
Parameters
$config : mixed

Config object or array

$required : array<string|int, mixed> = []

Required config items

Return values
mixed

addAsset()

Adds the provided asset to the internal asset collections

protected addAsset(string $type, string $path, array<string|int, mixed> $attributes) : mixed
Parameters
$type : string

The type of the asset: 'js' || 'css' || 'rss'

$path : string

The path to the asset

$attributes : array<string|int, mixed>

The attributes for the asset

Return values
mixed

controllerMethodExists()

Returns true in case if a specified method exists in the extended controller.

protected controllerMethodExists(string $methodName) : bool
Parameters
$methodName : string

Specifies the method name

Return values
bool

extensionHideField()

protected extensionHideField(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

extensionHideMethod()

protected extensionHideMethod(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

getAssetEntryBuildPath()

Internal helper, attaches a build code to an asset path

protected getAssetEntryBuildPath(array<string|int, mixed> $asset) : string
Parameters
$asset : array<string|int, mixed>

Stored asset array

Return values
string

getAssetScheme()

Internal helper, get asset scheme

protected getAssetScheme(string $asset) : string
Parameters
$asset : string

Specifies a path (URL) to the asset.

Return values
string

getLocalPath()

protected getLocalPath(string $relativePath) : mixed
Parameters
$relativePath : string
Return values
mixed

getSession()

Retrieves a widget related key/value pair from session data.

protected getSession([string $key = null ][, string $default = null ]) : string
Parameters
$key : string = null

Unique key for the data store.

$default : string = null

A default value to use when value is not found.

Return values
string

handleViewException()

Handle a view exception.

protected handleViewException(Exception $e, int $obLevel) : void
Parameters
$e : Exception
$obLevel : int
Return values
void

hideAction()

Protects a public method from being available as an controller action.

protected hideAction(mixed $methodName) : mixed

These methods could be defined in a controller to override a behavior default action. Such methods should be defined as public, to allow the behavior object to access it. By default public methods of a controller are considered as actions. To prevent this occurrence, methods should be hidden by using this method.

Parameters
$methodName : mixed

Specifies a method name.

Return values
mixed

makeSessionId()

Returns a unique session identifier for this widget and controller action.

protected makeSessionId() : string
Return values
string

putSession()

Saves a widget related key/value pair in to session data.

protected putSession(string $key, string $value) : void
Parameters
$key : string

Unique key for the data store.

$value : string

The value to store.

Return values
void

removeDuplicates()

Removes duplicate assets from the entire collection.

protected removeDuplicates() : void
Return values
void

Search results