Documentation

RelationController extends ControllerBehavior
in package
Uses FormModelSaver

Uses a combination of lists and forms for managing Model relations.

This behavior is implemented in the controller like so:

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

public $relationConfig = 'config_relation.yaml';

The $relationConfig property makes reference to the 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

PARAM_EXTRA_CONFIG  = '_relation_extra_config'
PARAM_FIELD  = '_relation_field'
PARAM_MODE  = '_relation_mode'
$assetPath  : string
$deferredBinding  : bool
$extendableStaticCalledClass  : string
$layout  : string
$readOnly  : bool
$relationModel  : Model
$relationName  : string
$relationObject  : Model
$relationType  : string
$sessionKey  : string
$suppressLayout  : bool
$vars  : array<string|int, mixed>
$actions  : array<string|int, mixed>
$alias  : string
$assets  : array<string|int, mixed>
$config  : array<string|int, mixed>
$configPath  : string
$controller  : Controller
$eventTarget  : string
$extensionCallbacks  : array<string|int, mixed>
$extensionHidden  : mixed
$extraConfig  : array<string|int, mixed>
$field  : Model
$forceManageMode  : string
$forceViewMode  : string
$foreignId  : int
$initialized  : bool
$layoutPath  : string
$manageFilterWidget  : Filter
$manageId  : int
$manageMode  : string
$manageTitle  : string
$manageWidget  : WidgetBase
$model  : Model
$modelsToSave  : array<string|int, mixed>
$originalConfig  : array<string|int, mixed>
$pivotWidget  : WidgetBase
$requiredConfig  : array<string|int, mixed>
$requiredProperties  : array<string|int, mixed>
$requiredRelationProperties  : array<string|int, mixed>
$searchWidget  : Search
$toolbarButtons  : array<string|int, mixed>
$toolbarWidget  : Toolbar
$viewFilterWidget  : Filter
$viewMode  : string
$viewModel  : Model
$viewPath  : string|array<string|int, mixed>
$viewWidget  : WidgetBase
__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
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.
initRelation()  : void
Prepare the widgets used by this behavior
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
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.
onRelationButtonAdd()  : mixed
onRelationButtonCreate()  : mixed
onRelationButtonDelete()  : mixed
onRelationButtonLink()  : mixed
onRelationButtonRemove()  : mixed
onRelationButtonUnlink()  : mixed
onRelationButtonUpdate()  : mixed
onRelationClickManageList()  : mixed
onRelationClickManageListPivot()  : mixed
onRelationClickViewList()  : mixed
onRelationManageAdd()  : mixed
Add an existing related model to the primary model
onRelationManageAddPivot()  : mixed
Add multiple items using a single pivot form.
onRelationManageCreate()  : mixed
Create a new related model
onRelationManageDelete()  : mixed
Delete an existing related model completely
onRelationManageForm()  : mixed
onRelationManagePivotCreate()  : mixed
onRelationManagePivotForm()  : mixed
onRelationManagePivotUpdate()  : mixed
onRelationManageRemove()  : mixed
Remove an existing related model from the primary model
onRelationManageUpdate()  : mixed
Updated an existing related model's fields
prepareVars()  : void
Prepares the view data.
relationExtendConfig()  : mixed
Provides an opportunity to manipulate the field configuration.
relationExtendManageFilterWidget()  : mixed
Provides an opportunity to manipulate the manage filter widget.
relationExtendManageWidget()  : mixed
Provides an opportunity to manipulate the manage widget.
relationExtendPivotWidget()  : mixed
Provides an opportunity to manipulate the pivot widget.
relationExtendRefreshResults()  : array<string|int, mixed>
The view widget is often refreshed when the manage widget makes a change, you can use this method to inject additional containers when this process occurs. Return an array with the extra values to send to the browser, eg:
relationExtendViewFilterWidget()  : mixed
Provides an opportunity to manipulate the view filter widget.
relationExtendViewWidget()  : mixed
Provides an opportunity to manipulate the view widget.
relationGetId()  : string
Returns a unique ID for this relation and field combination.
relationGetManageWidget()  : WidgetBase
Returns the manage widget used by this behavior.
relationGetSessionKey()  : mixed
Returns the active session key.
relationGetViewWidget()  : WidgetBase
Returns the view widget used by this behavior.
relationMakePartial()  : string
Controller accessor for making partials within this behavior.
relationRefresh()  : array<string|int, mixed>
Refreshes the relation container only, useful for returning in custom AJAX requests.
relationRender()  : string
Renders the relationship manager.
relationRenderToolbar()  : string
Renders the toolbar only.
relationRenderView()  : string
Renders the view only.
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
applyExtraConfig()  : mixed
Apply extra configuration
beforeAjax()  : mixed
The controller action is responsible for supplying the parent model so it's action must be fired. Additionally, each AJAX request must supply the relation's field name (_relation_field).
controllerMethodExists()  : bool
Returns true in case if a specified method exists in the extended controller.
deferPurgedSaveAttributes()  : void
Removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.
evalFormContext()  : mixed
Determine supplied form context.
evalManageMode()  : string
Determine the management mode based on the relation type and settings.
evalManageTitle()  : string
Determine the management mode popup title.
evalToolbarButtons()  : array<string|int, mixed>|null
Determine the default buttons based on the model relationship type.
evalViewMode()  : string
Determine the view mode based on the model relationship type.
extensionHideField()  : mixed
extensionHideMethod()  : mixed
findExistingRelationIds()  : mixed
Returns the existing record IDs for the relation.
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.
makeConfigForMode()  : mixed
Returns the configuration for a mode (view, manage, pivot) for an expected type (list, form). Uses fallback configuration.
makeFilterWidget()  : WidgetBase|null
Initialize a filter widget
makeManageWidget()  : mixed
makePivotWidget()  : mixed
makeSearchWidget()  : mixed
makeSessionId()  : string
Returns a unique session identifier for this widget and controller action.
makeToolbarWidget()  : mixed
makeViewWidget()  : mixed
prepareModelsToSave()  : array<string|int, mixed>
Takes a model and fills it with data from a multidimensional array.
putSession()  : void
Saves a widget related key/value pair in to session data.
removeDuplicates()  : void
Removes duplicate assets from the entire collection.
setModelAttributes()  : void
Sets a data collection to a model attributes, relations are also set.
validateField()  : string
Validates the supplied field and initializes the relation manager.

Constants

PARAM_EXTRA_CONFIG

public const PARAM_EXTRA_CONFIG = '_relation_extra_config'

Postback parameter for read only mode.

PARAM_FIELD

public const PARAM_FIELD = '_relation_field'

Postback parameter for the active relationship field.

PARAM_MODE

public const PARAM_MODE = '_relation_mode'

Postback parameter for the active management mode.

Properties

$assetPath

public string $assetPath

Specifies a path to the asset directory.

$deferredBinding

public bool $deferredBinding = false

Defers all binding actions using a session key when it is available.

$extendableStaticCalledClass

public static string $extendableStaticCalledClass = null

The calling class when using a static method.

$layout

public string $layout

Layout to use for the view.

$readOnly

public bool $readOnly = false

Disables the ability to add, update, delete or create relations.

$sessionKey

public string $sessionKey

Active session key, used for deferred bindings.

$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 = []

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.

$eventTarget

protected string $eventTarget

The target that triggered an AJAX event (button, list)

$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']]

$extraConfig

protected array<string|int, mixed> $extraConfig

Config provided by the relationRender method

$forceManageMode

protected string $forceManageMode

Force a certain manage mode.

$initialized

protected bool $initialized = false

Has the behavior been initialized.

$layoutPath

protected string $layoutPath

Specifies a path to the layout directory.

$manageMode

protected string $manageMode

Management of relation as list, form, or pivot.

$manageTitle

protected string $manageTitle

The title used for the manage popup.

$manageWidget

protected WidgetBase $manageWidget

Reference to the widget used for relation management.

$modelsToSave

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

List of prepared models that require saving.

$originalConfig

protected array<string|int, mixed> $originalConfig

Original configuration values

$pivotWidget

protected WidgetBase $pivotWidget

Reference to widget for relations with pivot data.

$requiredConfig

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

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

$requiredProperties

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

Properties that must exist in the controller using this behavior.

Tags
inheritDoc

$requiredRelationProperties

protected array<string|int, mixed> $requiredRelationProperties = ['label']

Properties that must exist for each relationship definition.

$searchWidget

protected Search $searchWidget

Reference to the search widget object.

$toolbarButtons

protected array<string|int, mixed> $toolbarButtons

The set of buttons to display in view mode.

$toolbarWidget

protected Toolbar $toolbarWidget

Reference to the toolbar widget object.

$viewMode

protected string $viewMode

Relation has many (multi) or has one (single).

$viewPath

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

Specifies a path to the views directory.

$viewWidget

protected WidgetBase $viewWidget

Reference to the widget used for viewing (list or form).

Methods

__construct()

Behavior constructor

public __construct(Controller $controller) : mixed
Parameters
$controller : Controller
Return values
mixed

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

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

initRelation()

Prepare the widgets used by this behavior

public initRelation(Model $model[, string $field = null ]) : void
Parameters
$model : Model
$field : string = null
Return values
void

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

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

onRelationButtonAdd()

public onRelationButtonAdd() : mixed
Return values
mixed

onRelationButtonCreate()

public onRelationButtonCreate() : mixed
Return values
mixed

onRelationButtonDelete()

public onRelationButtonDelete() : mixed
Return values
mixed
public onRelationButtonLink() : mixed
Return values
mixed

onRelationButtonRemove()

public onRelationButtonRemove() : mixed
Return values
mixed
public onRelationButtonUnlink() : mixed
Return values
mixed

onRelationButtonUpdate()

public onRelationButtonUpdate() : mixed
Return values
mixed

onRelationClickManageList()

public onRelationClickManageList() : mixed
Return values
mixed

onRelationClickManageListPivot()

public onRelationClickManageListPivot() : mixed
Return values
mixed

onRelationClickViewList()

public onRelationClickViewList() : mixed
Return values
mixed

onRelationManageAdd()

Add an existing related model to the primary model

public onRelationManageAdd() : mixed
Return values
mixed

onRelationManageAddPivot()

Add multiple items using a single pivot form.

public onRelationManageAddPivot() : mixed
Return values
mixed

onRelationManageCreate()

Create a new related model

public onRelationManageCreate() : mixed
Return values
mixed

onRelationManageDelete()

Delete an existing related model completely

public onRelationManageDelete() : mixed
Return values
mixed

onRelationManageForm()

public onRelationManageForm() : mixed
Return values
mixed

onRelationManagePivotCreate()

public onRelationManagePivotCreate() : mixed
Return values
mixed

onRelationManagePivotForm()

public onRelationManagePivotForm() : mixed
Return values
mixed

onRelationManagePivotUpdate()

public onRelationManagePivotUpdate() : mixed
Return values
mixed

onRelationManageRemove()

Remove an existing related model from the primary model

public onRelationManageRemove() : mixed
Return values
mixed

onRelationManageUpdate()

Updated an existing related model's fields

public onRelationManageUpdate() : mixed
Return values
mixed

prepareVars()

Prepares the view data.

public prepareVars() : void
Return values
void

relationExtendConfig()

Provides an opportunity to manipulate the field configuration.

public relationExtendConfig(object $config, string $field, Model $model) : mixed
Parameters
$config : object
$field : string
$model : Model
Return values
mixed

relationExtendManageFilterWidget()

Provides an opportunity to manipulate the manage filter widget.

public relationExtendManageFilterWidget(Filter $widget, string $field, Model $model) : mixed
Parameters
$widget : Filter
$field : string
$model : Model
Return values
mixed

relationExtendManageWidget()

Provides an opportunity to manipulate the manage widget.

public relationExtendManageWidget(WidgetBase $widget, string $field, Model $model) : mixed
Parameters
$widget : WidgetBase
$field : string
$model : Model
Return values
mixed

relationExtendPivotWidget()

Provides an opportunity to manipulate the pivot widget.

public relationExtendPivotWidget(WidgetBase $widget, string $field, Model $model) : mixed
Parameters
$widget : WidgetBase
$field : string
$model : Model
Return values
mixed

relationExtendRefreshResults()

The view widget is often refreshed when the manage widget makes a change, you can use this method to inject additional containers when this process occurs. Return an array with the extra values to send to the browser, eg:

public relationExtendRefreshResults(string $field) : array<string|int, mixed>

return ['#myCounter' => 'Total records: 6'];

Parameters
$field : string
Return values
array<string|int, mixed>

relationExtendViewFilterWidget()

Provides an opportunity to manipulate the view filter widget.

public relationExtendViewFilterWidget(Filter $widget, string $field, Model $model) : mixed
Parameters
$widget : Filter
$field : string
$model : Model
Return values
mixed

relationExtendViewWidget()

Provides an opportunity to manipulate the view widget.

public relationExtendViewWidget(WidgetBase $widget, string $field, Model $model) : mixed
Parameters
$widget : WidgetBase
$field : string
$model : Model
Return values
mixed

relationGetId()

Returns a unique ID for this relation and field combination.

public relationGetId([string $suffix = null ]) : string
Parameters
$suffix : string = null

A suffix to use with the identifier.

Return values
string

relationGetSessionKey()

Returns the active session key.

public relationGetSessionKey([mixed $force = false ]) : mixed
Parameters
$force : mixed = false
Return values
mixed

relationMakePartial()

Controller accessor for making partials within this behavior.

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

Partial contents

relationRefresh()

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

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

Relation definition.

Return values
array<string|int, mixed>

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

relationRender()

Renders the relationship manager.

public relationRender(string $field[, array<string|int, mixed> $options = [] ]) : string
Parameters
$field : string

The relationship field.

$options : array<string|int, mixed> = []
Return values
string

Rendered HTML for the relationship manager.

relationRenderToolbar()

Renders the toolbar only.

public relationRenderToolbar([string $field = null ]) : string
Parameters
$field : string = null

The relationship field.

Return values
string

Rendered HTML for the toolbar.

relationRenderView()

Renders the view only.

public relationRenderView([string $field = null ]) : string
Parameters
$field : string = null

The relationship field.

Return values
string

Rendered HTML for the view.

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

applyExtraConfig()

Apply extra configuration

protected applyExtraConfig(mixed $config[, mixed $field = null ]) : mixed
Parameters
$config : mixed
$field : mixed = null
Return values
mixed

beforeAjax()

The controller action is responsible for supplying the parent model so it's action must be fired. Additionally, each AJAX request must supply the relation's field name (_relation_field).

protected beforeAjax() : mixed
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

deferPurgedSaveAttributes()

Removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.

protected deferPurgedSaveAttributes(Model $model, array<string|int, mixed> $attributesToPurge) : void
Parameters
$model : Model

Model to adjust.

$attributesToPurge : array<string|int, mixed>

Attribute values to remove from the model.

Return values
void

evalFormContext()

Determine supplied form context.

protected evalFormContext([mixed $mode = 'manage' ][, mixed $exists = false ]) : mixed
Parameters
$mode : mixed = 'manage'
$exists : mixed = false
Return values
mixed

evalManageMode()

Determine the management mode based on the relation type and settings.

protected evalManageMode() : string
Return values
string

evalManageTitle()

Determine the management mode popup title.

protected evalManageTitle() : string
Return values
string

evalToolbarButtons()

Determine the default buttons based on the model relationship type.

protected evalToolbarButtons() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

evalViewMode()

Determine the view mode based on the model relationship type.

protected evalViewMode() : string
Return values
string

extensionHideField()

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

extensionHideMethod()

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

findExistingRelationIds()

Returns the existing record IDs for the relation.

protected findExistingRelationIds([mixed $checkIds = null ]) : mixed
Parameters
$checkIds : mixed = null
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

makeConfigForMode()

Returns the configuration for a mode (view, manage, pivot) for an expected type (list, form). Uses fallback configuration.

protected makeConfigForMode([mixed $mode = 'view' ][, mixed $type = 'list' ][, mixed $throwException = true ]) : mixed
Parameters
$mode : mixed = 'view'
$type : mixed = 'list'
$throwException : mixed = true
Return values
mixed

makeFilterWidget()

Initialize a filter widget

protected makeFilterWidget( $type) : WidgetBase|null
Parameters
$type :

string Either 'manage' or 'view'

Return values
WidgetBase|null

makeManageWidget()

protected makeManageWidget() : mixed
Return values
mixed

makeSearchWidget()

protected makeSearchWidget() : mixed
Return values
mixed

makeSessionId()

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

protected makeSessionId() : string
Return values
string

makeToolbarWidget()

protected makeToolbarWidget() : mixed
Return values
mixed

prepareModelsToSave()

Takes a model and fills it with data from a multidimensional array.

protected prepareModelsToSave(Model $model, array<string|int, mixed> $saveData) : array<string|int, mixed>

If an attribute is found to be a relationship, that relationship is also filled.

$modelsToSave = $this->prepareModelsToSave($model, [...]);

foreach ($modelsToSave as $modelToSave) {
    $modelToSave->save();
}
Parameters
$model : Model

Model to fill.

$saveData : array<string|int, mixed>

Attribute values to fill model.

Return values
array<string|int, mixed>

The collection of models to save.

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

setModelAttributes()

Sets a data collection to a model attributes, relations are also set.

protected setModelAttributes(Model $model, array<string|int, mixed> $saveData) : void
Parameters
$model : Model

Model to fill.

$saveData : array<string|int, mixed>

Attribute values to fill model.

Return values
void

validateField()

Validates the supplied field and initializes the relation manager.

protected validateField([string $field = null ]) : string
Parameters
$field : string = null

The relationship field.

Return values
string

The active field name.

Search results