class FormController extends ControllerAction

Form Controller Class

Traits

Widget Maker Trait Class

Extension trait

Constants

CONTEXT_CREATE

CONTEXT_EDIT

CONTEXT_PREVIEW

Properties

string $configPath from  ConfigMaker
protected $configFileExtension from  ConfigMaker
array $vars from  ViewMaker
array $viewPath from  ViewMaker
array $layoutPath from  ViewMaker
array $partialPath from  ViewMaker
string $layout from  ViewMaker
bool $suppressLayout from  ViewMaker
protected $viewFileExtension from  ViewMaker
static protected array $extensionCallbacks from  ExtensionTrait
static string $extendableStaticCalledClass from  ExtensionTrait
protected $extensionHidden from  ExtensionTrait
protected AdminController|FormController $controller
protected array $config from  ControllerAction
protected $requiredProperties
array $formConfig

Define controller list configuration array.

protected Form $formWidget
protected BaseWidget $toolbarWidget
protected array $requiredConfig
protected string $context
protected Model $model
protected Model $request
protected array $modelsToSave

Methods

array
loadConfig(array $configFile = [], array $requiredConfig = [], null $index = null)

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

array
makeConfig(string|array $configFile, array $requiredConfig = [])

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

array
mergeConfig($configLeft, $configRight)

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

string
getConfigPath(string $fileName, mixed $configPath = null)

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.

string
guessConfigPath(string $suffix = '')

Guess the package path for the called class.

string
guessConfigPathFrom(string $class, string $suffix = '')

Guess the package path from a specified class.

getViewPath($view, $viewPath = null)

No description

guessViewFileExtension($path)

No description

string
guessViewPath(string $suffix = '', bool $isPublic = FALSE)

Guess the package path from a specified class.

mixed
makeLayout(string $name = null, array $vars = [], bool $throwException = TRUE)

Render a layout.

string
makeView(string $view)

Loads a view with the name specified.

mixed
makePartial(string $partial, array $vars = [], bool $throwException = TRUE)

Render a partial file contents located in the views or partial folder.

string
makeFileContent(string $filePath, array $extraParams = [])

Includes a file path using output buffering.

compileFileContent($filePath)

No description

void
handleViewException(Exception $e, int $obLevel)

Handle a view exception.

array
gatherViewData($data)

Get the data bound to the view instance.

makeWidget(string $class, array $widgetConfig = [])

Makes a widget object with the supplied configuration ex. model config

makeFormWidget(string $class, mixed $fieldConfig = [], array $widgetConfig = [])

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

static void
extensionExtendCallback(callable $callback)

Helper method for ::extend() static method

extensionHideField($name)

No description

extensionHideMethod($name)

No description

extensionIsHiddenField($name)

No description

extensionIsHiddenMethod($name)

No description

static 
getCalledExtensionClass()

No description

__construct(Controller $controller)

FormController constructor.

setConfig(string|array $config, array $required = [])

Sets the widget configuration values

mixed
getConfig(string $name = null, mixed $default = null)

Get the widget configuration values.

hideAction($methodName)

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

formValidate($model, $form)

Called to validate create or edit form.

formBeforeSave($model)

Called before the creation or updating form is saved.

formAfterSave($model)

Called after the creation or updating form is saved.

formBeforeCreate($model)

Called before the creation form is saved.

formAfterCreate($model)

Called after the creation form is saved.

formBeforeUpdate($model)

Called before the updating form is saved.

formAfterUpdate($model)

Called after the updating form is saved.

formAfterDelete($model)

Called after the form model is deleted.

formFindModelObject(string $recordId)

Finds a Model record by its primary identifier, used by edit actions. This logic can be changed by overriding it in the controller.

formCreateModelObject()

Creates a new instance of a form model. This logic can be changed by overriding it in the controller.

void
formExtendFieldsBefore(Form $host)

Called before the form fields are defined.

void
formExtendFields(Form $host, $fields)

Called after the form fields are defined.

array
formExtendRefreshData(Form $host, array $saveData)

Called before the form is refreshed, should return an array of additional save data.

array
formExtendRefreshFields(Form $host, array $fields)

Called when the form is refreshed, giving the opportunity to modify the form fields.

array
formExtendRefreshResults(Form $host, array $result)

Called after the form is refreshed, should return an array of additional result parameters.

formExtendModel(Model $model)

Extend supplied model used by create and edit actions, the model can be altered by overriding it in the controller.

void
formExtendQuery(Builder $query)

Extend the query used for finding the form model. Extra conditions can be applied to the query, for example, $query->withTrashed();

formExtendConfig($formConfig)

No description

static void
extendFormFields(callable $callback)

Static helper for extending form fields.

void
initForm(Model $model, null $context = null)

Prepare the widgets used by this action

prepareVars($model)

Prepares common form data

create($context = null)

No description

create_onSave($context = null)

No description

edit($context = null, $recordId = null)

No description

edit_onSave($context = null, $recordId = null)

No description

edit_onDelete($context = null, $recordId = null)

No description

preview($context = null, $recordId = null)

No description

string
renderForm(array $options = [])

Render the form.

getFormModel()

Returns the model initialized by this form behavior.

string
getFormContext()

Returns the form context from the postback or configuration.

setFormTitle($default)

No description

createModel()

Internal method, prepare the form model object

Redirect
makeRedirect(string $context = null, Model $model = null)

Returns a Redirect object based on supplied context and parses the model primary key.

string
getRedirectUrl(string $context = null)

Internal method, returns a redirect URL from the config based on supplied context. Otherwise the default redirect is used.

prepareModelsToSave($model, $saveData)

No description

void
setModelAttributes(Model $model, array $saveData)

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

validateFormRequest($model)

No description

resolveFormRequest($requestClass)

No description

Details

in ConfigMaker at line 27
array loadConfig(array $configFile = [], array $requiredConfig = [], null $index = null)

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

Parameters

array $configFile
array $requiredConfig
null $index

Return Value

array

in ConfigMaker at line 46
array makeConfig(string|array $configFile, array $requiredConfig = [])

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

Parameters

string|array $configFile
array $requiredConfig

Return Value

array

Exceptions

SystemException

in ConfigMaker at line 97
array mergeConfig($configLeft, $configRight)

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

Parameters

$configLeft
$configRight

Return Value

array

The config array

in ConfigMaker at line 116
string getConfigPath(string $fileName, mixed $configPath = null)

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.

Parameters

string $fileName

File to load.

mixed $configPath

Explicitly define a config path.

Return Value

string

Full path to the config file.

in ConfigMaker at line 154
string guessConfigPath(string $suffix = '')

Guess the package path for the called class.

Parameters

string $suffix

An extra path to attach to the end

Return Value

string

in ConfigMaker at line 169
string guessConfigPathFrom(string $class, string $suffix = '')

Guess the package path from a specified class.

Parameters

string $class

Class to guess path from.

string $suffix

An extra path to attach to the end

Return Value

string

in ViewMaker at line 50
getViewPath($view, $viewPath = null)

No description

Parameters

$view
$viewPath

in ViewMaker at line 78
guessViewFileExtension($path)

No description

Parameters

$path

in ViewMaker at line 100
string guessViewPath(string $suffix = '', bool $isPublic = FALSE)

Guess the package path from a specified class.

Parameters

string $suffix

An extra path to attach to the end

bool $isPublic

Return Value

string

in ViewMaker at line 121
mixed makeLayout(string $name = null, array $vars = [], bool $throwException = TRUE)

Render a layout.

Parameters

string $name

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

array $vars

Parameter variables to pass to the view.

bool $throwException

Throw an exception if the layout is not found

Return Value

mixed

The layout contents, or false.

Exceptions

SystemException

in ViewMaker at line 149
string makeView(string $view)

Loads a view with the name specified.

Applies layout if its name is provided by the parent object. The view file must be situated in the views directory, and has the extension "htm" or "php".

Parameters

string $view

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

Return Value

string

in ViewMaker at line 173
mixed makePartial(string $partial, array $vars = [], bool $throwException = TRUE)

Render a partial file contents located in the views or partial folder.

Parameters

string $partial

The view to load.

array $vars

Parameter variables to pass to the view.

bool $throwException

Throw an exception if the partial is not found.

Return Value

mixed

Partial contents or false if not throwing an exception.

Exceptions

SystemException

in ViewMaker at line 201
string makeFileContent(string $filePath, array $extraParams = [])

Includes a file path using output buffering.

Ensures that vars are available.

Parameters

string $filePath

Absolute path to the view file.

array $extraParams

Parameters that should be available to the view.

Return Value

string

in ViewMaker at line 239
compileFileContent($filePath)

No description

Parameters

$filePath

in ViewMaker at line 260
protected void handleViewException(Exception $e, int $obLevel)

Handle a view exception.

Parameters

Exception $e
int $obLevel

Return Value

void

in ViewMaker at line 275
protected array gatherViewData($data)

Get the data bound to the view instance.

Parameters

$data

Return Value

array

in WidgetMaker at line 24
BaseWidget makeWidget(string $class, array $widgetConfig = [])

Makes a widget object with the supplied configuration ex. model config

Parameters

string $class

Widget class name

array $widgetConfig

An array of config.

Return Value

BaseWidget

The widget object

in WidgetMaker at line 47
BaseFormWidget makeFormWidget(string $class, mixed $fieldConfig = [], array $widgetConfig = [])

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

Parameters

string $class

Widget class name

mixed $fieldConfig

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

array $widgetConfig

An array of config.

Return Value

BaseFormWidget

The widget object

Exceptions

Exception

in ExtensionTrait at line 32
extensionApplyInitCallbacks()

No description

in ExtensionTrait at line 51
static void extensionExtendCallback(callable $callback)

Helper method for ::extend() static method

Parameters

callable $callback

Return Value

void

in ExtensionTrait at line 64
protected extensionHideField($name)

No description

Parameters

$name

in ExtensionTrait at line 69
protected extensionHideMethod($name)

No description

Parameters

$name

in ExtensionTrait at line 74
extensionIsHiddenField($name)

No description

Parameters

$name

in ExtensionTrait at line 79
extensionIsHiddenMethod($name)

No description

Parameters

$name

in ExtensionTrait at line 84
static getCalledExtensionClass()

No description

at line 97
__construct(Controller $controller)

FormController constructor.

Parameters

Controller $controller

Exceptions

Exception

in ControllerAction at line 65
setConfig(string|array $config, array $required = [])

Sets the widget configuration values

Parameters

string|array $config
array $required

Required config items

in ControllerAction at line 78
mixed getConfig(string $name = null, mixed $default = null)

Get the widget configuration values.

Parameters

string $name

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

mixed $default

Default value if nothing is found

Return Value

mixed

in ControllerAction at line 103
protected hideAction($methodName)

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

Parameters

$methodName

in FormExtendable at line 13
formValidate($model, $form)

Called to validate create or edit form.

Parameters

$model
$form

in FormExtendable at line 20
formBeforeSave($model)

Called before the creation or updating form is saved.

Parameters

$model

in FormExtendable at line 27
formAfterSave($model)

Called after the creation or updating form is saved.

Parameters

$model

in FormExtendable at line 34
formBeforeCreate($model)

Called before the creation form is saved.

Parameters

$model

in FormExtendable at line 41
formAfterCreate($model)

Called after the creation form is saved.

Parameters

$model

in FormExtendable at line 48
formBeforeUpdate($model)

Called before the updating form is saved.

Parameters

$model

in FormExtendable at line 55
formAfterUpdate($model)

Called after the updating form is saved.

Parameters

$model

in FormExtendable at line 62
formAfterDelete($model)

Called after the form model is deleted.

Parameters

$model

in FormExtendable at line 75
formFindModelObject(string $recordId)

Finds a Model record by its primary identifier, used by edit actions. This logic can be changed by overriding it in the controller.

Parameters

string $recordId

Exceptions

Exception

in FormExtendable at line 108
formCreateModelObject()

Creates a new instance of a form model. This logic can be changed by overriding it in the controller.

in FormExtendable at line 120
void formExtendFieldsBefore(Form $host)

Called before the form fields are defined.

Parameters

Form $host

The hosting form widget

Return Value

void

in FormExtendable at line 131
void formExtendFields(Form $host, $fields)

Called after the form fields are defined.

Parameters

Form $host

The hosting form widget

$fields

Return Value

void

in FormExtendable at line 143
array formExtendRefreshData(Form $host, array $saveData)

Called before the form is refreshed, should return an array of additional save data.

Parameters

Form $host

The hosting form widget

array $saveData

Current save data

Return Value

array

in FormExtendable at line 155
array formExtendRefreshFields(Form $host, array $fields)

Called when the form is refreshed, giving the opportunity to modify the form fields.

Parameters

Form $host

The hosting form widget

array $fields

Current form fields

Return Value

array

in FormExtendable at line 167
array formExtendRefreshResults(Form $host, array $result)

Called after the form is refreshed, should return an array of additional result parameters.

Parameters

Form $host

The hosting form widget

array $result

Current result parameters.

Return Value

array

in FormExtendable at line 179
formExtendModel(Model $model)

Extend supplied model used by create and edit actions, the model can be altered by overriding it in the controller.

Parameters

Model $model

in FormExtendable at line 191
void formExtendQuery(Builder $query)

Extend the query used for finding the form model. Extra conditions can be applied to the query, for example, $query->withTrashed();

Parameters

Builder $query

Return Value

void

in FormExtendable at line 195
formExtendConfig($formConfig)

No description

Parameters

$formConfig

in FormExtendable at line 206
static void extendFormFields(callable $callback)

Static helper for extending form fields.

Parameters

callable $callback

Return Value

void

at line 145
void initForm(Model $model, null $context = null)

Prepare the widgets used by this action

Parameters

Model $model
null $context

Return Value

void

Exceptions

Exception

at line 217
protected prepareVars($model)

Prepares common form data

Parameters

$model

at line 224
create($context = null)

No description

Parameters

$context

at line 240
create_onSave($context = null)

No description

Parameters

$context

at line 274
edit($context = null, $recordId = null)

No description

Parameters

$context
$recordId

at line 290
edit_onSave($context = null, $recordId = null)

No description

Parameters

$context
$recordId

at line 324
edit_onDelete($context = null, $recordId = null)

No description

Parameters

$context
$recordId

at line 346
preview($context = null, $recordId = null)

No description

Parameters

$context
$recordId

at line 373
string renderForm(array $options = [])

Render the form.

Parameters

array $options

Custom options to pass to the form widget.

Return Value

string

Rendered HTML for the form.

Exceptions

Exception

at line 392
Model getFormModel()

Returns the model initialized by this form behavior.

Return Value

Model

at line 401
string getFormContext()

Returns the form context from the postback or configuration.

Return Value

string

at line 409
protected setFormTitle($default)

No description

Parameters

$default

at line 425
protected Model createModel()

Internal method, prepare the form model object

Return Value

Model

at line 440
Redirect makeRedirect(string $context = null, Model $model = null)

Returns a Redirect object based on supplied context and parses the model primary key.

Parameters

string $context

Redirect context, eg: create, edit, delete

Model $model

The active model to parse in it's ID and attributes.

Return Value

Redirect

at line 472
protected string getRedirectUrl(string $context = null)

Internal method, returns a redirect URL from the config based on supplied context. Otherwise the default redirect is used.

Parameters

string $context

Redirect context, eg: create, edit, delete.

Return Value

string

at line 486
protected prepareModelsToSave($model, $saveData)

No description

Parameters

$model
$saveData

at line 503
protected void setModelAttributes(Model $model, array $saveData)

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

Parameters

Model $model

Model to save to

array $saveData

Data to save.

Return Value

void

at line 528
protected validateFormRequest($model)

No description

Parameters

$model

at line 541
protected resolveFormRequest($requestClass)

No description

Parameters

$requestClass