FormController
extends ControllerBehavior
in package
Uses
FormModelSaver
Adds features for working with backend forms. This behavior will inject CRUD actions to the controller -- including create, update and preview -- along with some relevant AJAX handlers.
Each action supports a custom context code, allowing fields to be displayed or hidden on a contextual basis, as specified by the form field definitions or some other custom logic.
This behavior is implemented in the controller like so:
public $implement = [
'Backend.Behaviors.FormController',
];
public $formConfig = 'config_form.yaml';
The $formConfig property makes reference to the form configuration
values as either a YAML file, located in the controller view directory,
or directly as a PHP array.
Tags
Table of Contents
- CONTEXT_CREATE = 'create'
- CONTEXT_PREVIEW = 'preview'
- CONTEXT_UPDATE = 'update'
- $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
- $context : string
- $controller : Controller|FormController
- $extensionCallbacks : array<string|int, mixed>
- $extensionHidden : mixed
- $formWidget : Form
- $layoutPath : string
- $model : Model|Model
- $modelsToSave : array<string|int, mixed>
- $requiredConfig : array<string|int, mixed>
- $requiredProperties : array<string|int, mixed>
- $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
- create() : void
- Controller "create" action used for creating new model records.
- create_onSave() : RedirectResponse|void
- AJAX handler "onSave" called from the create action and primarily used for creating new records.
- extend() : mixed
- extendFormFields() : void
- Static helper for extending form fields.
- 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.
- formAfterCreate() : mixed
- Called after the creation form is saved.
- formAfterDelete() : mixed
- Called after the form model is deleted.
- formAfterSave() : mixed
- Called after the creation or updating form is saved.
- formAfterUpdate() : mixed
- Called after the updating form is saved.
- formBeforeCreate() : mixed
- Called before the creation form is saved.
- formBeforeSave() : mixed
- Called before the creation or updating form is saved.
- formBeforeUpdate() : mixed
- Called before the updating form is saved.
- formCreateModelObject() : Model|Model
- Creates a new instance of a form model. This logic can be changed by overriding it in the controller.
- formExtendFields() : void
- Called after the form fields are defined.
- formExtendFieldsBefore() : void
- Called before the form fields are defined.
- formExtendModel() : Model|Model|void
- Extend supplied model used by create and update actions, the model can be altered by overriding it in the controller.
- formExtendQuery() : void
- Extend the query used for finding the form model. Extra conditions can be applied to the query, for example, $query->withTrashed();
- formExtendRefreshData() : array<string|int, mixed>|void
- Called before the form is refreshed, should return an array of additional save data.
- formExtendRefreshFields() : array<string|int, mixed>|void
- Called when the form is refreshed, giving the opportunity to modify the form fields.
- formExtendRefreshResults() : array<string|int, mixed>|void
- Called after the form is refreshed, should return an array of additional result parameters.
- formFindModelObject() : Model|Model
- Finds a Model record by its primary identifier, used by update actions. This logic can be changed by overriding it in the controller.
- formGetContext() : string
- Returns the active form context, either obtained from the postback variable called `form_context` or detected from the configuration, or routing parameters.
- formGetId() : string
- Returns a unique ID for the form widget used by this behavior.
- formGetModel() : Model|Model
- Returns the model initialized by this form behavior.
- formGetRedirectUrl() : string
- Returns a redirect URL from the config based on supplied context.
- formGetSessionKey() : string
- Helper to get the form session key.
- formGetWidget() : Form
- Returns the form widget used by this behavior.
- formHasOutsideFields() : bool
- View helper to check if a form tab has fields in the non-tabbed section (outside fields).
- formHasPrimaryTabs() : bool
- View helper to check if a form tab has fields in the primary tab section.
- formHasSecondaryTabs() : bool
- View helper to check if a form tab has fields in the secondary tab section.
- formRender() : string
- Method to render the prepared form markup. This method is usually called from a view file.
- formRenderField() : string
- View helper to render a single form field.
- formRenderOutsideFields() : string
- View helper to render the form fields belonging to the non-tabbed section (outside form fields).
- formRenderPreview() : string
- View helper to render the form in preview mode.
- formRenderPrimaryTabs() : string
- View helper to render the form fields belonging to the primary tabs section.
- formRenderSecondaryTabs() : string
- View helper to render the form fields belonging to the secondary tabs section.
- 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.
- initForm() : void
- Initialize the form configuration against a model and context value.
- 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.
- makeRedirect() : RedirectResponse
- Returns a Redirect object based on supplied context and parses the model primary key.
- 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.
- preview() : void
- Controller "preview" action used for viewing existing model records.
- resetSession() : void
- Resets all session data related to this widget.
- setConfig() : mixed
- Sets the configuration values
- update() : void
- Controller "update" action used for updating existing model records.
- update_onDelete() : RedirectResponse|void
- AJAX handler "onDelete" called from the update action and used for deleting existing records.
- update_onSave() : RedirectResponse|void
- AJAX handler "onSave" called from the update action and primarily used for updating existing records.
- 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.
- createModel() : Model|Model
- Internal method used to prepare the form model object.
- deferPurgedSaveAttributes() : void
- Removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.
- extensionHideField() : mixed
- extensionHideMethod() : mixed
- getAssetEntryBuildPath() : string
- Internal helper, attaches a build code to an asset path
- getAssetScheme() : string
- Internal helper, get asset scheme
- getLang() : string
- Parses in some default variables to a language string defined in config.
- 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.
- prepareModelsToSave() : array<string|int, mixed>
- Takes a model and fills it with data from a multidimensional array.
- prepareVars() : mixed
- Prepares commonly used view data.
- 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.
Constants
CONTEXT_CREATE
public
string
CONTEXT_CREATE
= 'create'
Default context for "create" pages.
CONTEXT_PREVIEW
public
string
CONTEXT_PREVIEW
= 'preview'
Default context for "preview" pages.
CONTEXT_UPDATE
public
string
CONTEXT_UPDATE
= 'update'
Default context for "update" pages.
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
= ['create', 'update', 'preview']
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.
$config
protected
array<string|int, mixed>
$config
Supplied configuration.
$configPath
protected
string
$configPath
Specifies a path to the config directory.
$context
protected
string
$context
The context to pass to the form widget.
$controller
protected
Controller|FormController
$controller
Reference to the back end controller.
$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']]
$formWidget
protected
Form
$formWidget
Reference to the widget object.
$layoutPath
protected
string
$layoutPath
Specifies a path to the layout directory.
$model
protected
Model|Model
$model
The initialized model used by the form.
$modelsToSave
protected
array<string|int, mixed>
$modelsToSave
= []
List of prepared models that require saving.
$requiredConfig
protected
array<string|int, mixed>
$requiredConfig
= ['modelClass', 'form']
Configuration values that must exist when applying the primary config file.
- modelClass: Class name for the model
- form: Form field definitions
$requiredProperties
protected
array<string|int, mixed>
$requiredProperties
= ['formConfig']
Properties that must exist in the controller using this behavior.
Tags
$viewPath
protected
string|array<string|int, mixed>
$viewPath
Specifies a path to the views directory.
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 —create()
Controller "create" action used for creating new model records.
public
create([string $context = null ]) : void
Parameters
- $context : string = null
-
Form context
Return values
void —create_onSave()
AJAX handler "onSave" called from the create action and primarily used for creating new records.
public
create_onSave([string $context = null ]) : RedirectResponse|void
This handler will invoke the unique controller overrides
formBeforeCreate and formAfterCreate.
Parameters
- $context : string = null
-
Form context
Return values
RedirectResponse|void —extend()
public
static extend(callable $callback) : mixed
Parameters
- $callback : callable
Return values
mixed —extendFormFields()
Static helper for extending form fields.
public
static extendFormFields(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 —formAfterCreate()
Called after the creation form is saved.
public
formAfterCreate(mixed $model) : mixed
Parameters
- $model : mixed
Return values
mixed —formAfterDelete()
Called after the form model is deleted.
public
formAfterDelete(mixed $model) : mixed
Parameters
- $model : mixed
Return values
mixed —formAfterSave()
Called after the creation or updating form is saved.
public
formAfterSave(mixed $model) : mixed
Parameters
- $model : mixed
Return values
mixed —formAfterUpdate()
Called after the updating form is saved.
public
formAfterUpdate(mixed $model) : mixed
Parameters
- $model : mixed
Return values
mixed —formBeforeCreate()
Called before the creation form is saved.
public
formBeforeCreate(mixed $model) : mixed
Parameters
- $model : mixed
Return values
mixed —formBeforeSave()
Called before the creation or updating form is saved.
public
formBeforeSave(mixed $model) : mixed
Parameters
- $model : mixed
Return values
mixed —formBeforeUpdate()
Called before the updating form is saved.
public
formBeforeUpdate(mixed $model) : mixed
Parameters
- $model : mixed
Return values
mixed —formCreateModelObject()
Creates a new instance of a form model. This logic can be changed by overriding it in the controller.
public
formCreateModelObject() : Model|Model
Return values
Model|Model —formExtendFields()
Called after the form fields are defined.
public
formExtendFields(Form $host, array<string|int, mixed> $fields) : void
Parameters
- $host : Form
-
The hosting form widget
- $fields : array<string|int, mixed>
-
Array of all defined form field objects (\Backend\Classes\FormField)
Return values
void —formExtendFieldsBefore()
Called before the form fields are defined.
public
formExtendFieldsBefore(Form $host) : void
Parameters
- $host : Form
-
The hosting form widget
Return values
void —formExtendModel()
Extend supplied model used by create and update actions, the model can be altered by overriding it in the controller.
public
formExtendModel(Model|Model $model) : Model|Model|void
Parameters
Return values
Model|Model|void —formExtendQuery()
Extend the query used for finding the form model. Extra conditions can be applied to the query, for example, $query->withTrashed();
public
formExtendQuery(Builder|Builder $query) : void
Parameters
Return values
void —formExtendRefreshData()
Called before the form is refreshed, should return an array of additional save data.
public
formExtendRefreshData(Form $host, array<string|int, mixed> $saveData) : array<string|int, mixed>|void
Parameters
- $host : Form
-
The hosting form widget
- $saveData : array<string|int, mixed>
-
Current save data
Return values
array<string|int, mixed>|void —formExtendRefreshFields()
Called when the form is refreshed, giving the opportunity to modify the form fields.
public
formExtendRefreshFields(Form $host, array<string|int, mixed> $fields) : array<string|int, mixed>|void
Parameters
- $host : Form
-
The hosting form widget
- $fields : array<string|int, mixed>
-
Current form fields
Return values
array<string|int, mixed>|void —formExtendRefreshResults()
Called after the form is refreshed, should return an array of additional result parameters.
public
formExtendRefreshResults(Form $host, array<string|int, mixed> $result) : array<string|int, mixed>|void
Parameters
- $host : Form
-
The hosting form widget
- $result : array<string|int, mixed>
-
Current result parameters.
Return values
array<string|int, mixed>|void —formFindModelObject()
Finds a Model record by its primary identifier, used by update actions. This logic can be changed by overriding it in the controller.
public
formFindModelObject(string $recordId) : Model|Model
Parameters
- $recordId : string
Tags
Return values
Model|Model —formGetContext()
Returns the active form context, either obtained from the postback variable called `form_context` or detected from the configuration, or routing parameters.
public
formGetContext() : string
Return values
string —formGetId()
Returns a unique ID for the form widget used by this behavior.
public
formGetId([string $suffix = null ]) : string
This is useful for dealing with identifiers in the markup.
<div id="<?= $this->formGetId()">...</div>
A suffix may be used passed as the first argument to reuse the identifier in other areas.
<button id="<?= $this->formGetId('button')">...</button>
Parameters
- $suffix : string = null
Return values
string —formGetModel()
Returns the model initialized by this form behavior.
public
formGetModel() : Model|Model
The model will be provided by one of the page actions or AJAX
handlers via the initForm method.
Return values
Model|Model —formGetRedirectUrl()
Returns a redirect URL from the config based on supplied context.
public
formGetRedirectUrl([string $context = null ][, Model $model = null ]) : string
Otherwise the default redirect is used. Relative URLs are treated as backend URLs.
Parameters
- $context : string = null
-
Redirect context, eg: create, update, delete.
- $model : Model = null
-
The active model.
Return values
string —formGetSessionKey()
Helper to get the form session key.
public
formGetSessionKey() : string
Return values
string —formGetWidget()
Returns the form widget used by this behavior.
public
formGetWidget() : Form
Return values
Form —formHasOutsideFields()
View helper to check if a form tab has fields in the non-tabbed section (outside fields).
public
formHasOutsideFields() : bool
<!-- Do something -->
Return values
bool —formHasPrimaryTabs()
View helper to check if a form tab has fields in the primary tab section.
public
formHasPrimaryTabs() : bool
<!-- Do something -->
Return values
bool —formHasSecondaryTabs()
View helper to check if a form tab has fields in the secondary tab section.
public
formHasSecondaryTabs() : bool
<!-- Do something -->
Return values
bool —formRender()
Method to render the prepared form markup. This method is usually called from a view file.
public
formRender([array<string|int, mixed> $options = [] ]) : string
The first argument supports an array of render options. The supported
options can be found via the render method of the Form widget class.
<?= $this->formRender(['preview' => true, section' => 'primary']) ?>
Parameters
- $options : array<string|int, mixed> = []
-
Render options
Tags
Return values
string —Rendered HTML for the form.
formRenderField()
View helper to render a single form field.
public
formRenderField(string $name[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
Field name
- $options : array<string|int, mixed> = []
-
(e.g. ['useContainer'=>false])
Return values
string —HTML markup
formRenderOutsideFields()
View helper to render the form fields belonging to the non-tabbed section (outside form fields).
public
formRenderOutsideFields() : string
Tags
Return values
string —HTML markup
formRenderPreview()
View helper to render the form in preview mode.
public
formRenderPreview() : string
Tags
Return values
string —The form HTML markup.
formRenderPrimaryTabs()
View helper to render the form fields belonging to the primary tabs section.
public
formRenderPrimaryTabs() : string
Tags
Return values
string —HTML markup
formRenderSecondaryTabs()
View helper to render the form fields belonging to the secondary tabs section.
public
formRenderSecondaryTabs() : string
Tags
Return values
string —HTML markup
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 —initForm()
Initialize the form configuration against a model and context value.
public
initForm(Model|Model $model[, string $context = null ]) : void
This will process the configuration found in the $formConfig property
and prepare the Form widget, which is the underlying tool used for
actually rendering the form. The model used by this form is passed
to this behavior via this method as the first argument.
Parameters
Tags
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.
makeRedirect()
Returns a Redirect object based on supplied context and parses the model primary key.
public
makeRedirect([string $context = null ][, Model|Model $model = null ]) : RedirectResponse
Parameters
- $context : string = null
-
Redirect context, eg: create, update, delete
- $model : Model|Model = null
-
The active model to parse in it's ID and attributes.
Return values
RedirectResponse —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
preview()
Controller "preview" action used for viewing existing model records.
public
preview([int $recordId = null ][, string $context = null ]) : void
This action takes a record identifier (primary key of the model) to locate the record used for sourcing the existing preview data.
Parameters
- $recordId : int = null
-
Record identifier
- $context : string = null
-
Form context
Return values
void —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 —update()
Controller "update" action used for updating existing model records.
public
update([int $recordId = null ][, string $context = null ]) : void
This action takes a record identifier (primary key of the model) to locate the record used for sourcing the existing form values.
Parameters
- $recordId : int = null
-
Record identifier
- $context : string = null
-
Form context
Return values
void —update_onDelete()
AJAX handler "onDelete" called from the update action and used for deleting existing records.
public
update_onDelete([int $recordId = null ]) : RedirectResponse|void
This handler will invoke the unique controller override
formAfterDelete.
Parameters
- $recordId : int = null
-
Record identifier
Tags
Return values
RedirectResponse|void —update_onSave()
AJAX handler "onSave" called from the update action and primarily used for updating existing records.
public
update_onSave([int $recordId = null ][, string $context = null ]) : RedirectResponse|void
This handler will invoke the unique controller overrides
formBeforeUpdate and formAfterUpdate.
Parameters
- $recordId : int = null
-
Record identifier
- $context : string = null
-
Form context
Tags
Return values
RedirectResponse|void —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 —createModel()
Internal method used to prepare the form model object.
protected
createModel() : Model|Model
Return values
Model|Model —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 —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 —getLang()
Parses in some default variables to a language string defined in config.
protected
getLang(string $name[, string $default = null ][, array<string|int, mixed> $extras = [] ]) : string
Parameters
- $name : string
-
Configuration property containing the language string
- $default : string = null
-
A default language string to use if the config is not found
- $extras : array<string|int, mixed> = []
-
Any extra params to include in the language string variables
Return values
string —The translated 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 —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.
prepareVars()
Prepares commonly used view data.
protected
prepareVars(Model|Model $model) : mixed
Parameters
Return values
mixed —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.