Backend\Behaviors\FormController

Source: ~/modules/backend/behaviors/FormController.php

Extends:

Form Controller Behavior Adds features for working with backend forms.

Public properties

There are no public properties in the class.

Show inhertied public properties

Inherited public properties

Protected properties

protected Backend\Classes\Controller|FormController $controller

Reference to the back end controller.

protected Backend\Widgets\Form $formWidget

Reference to the widget object.

protected $requiredProperties

Properties that must exist in the controller using this behavior.

protected array $requiredConfig

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

  • modelClass: Class name for the model
  • form: Form field definitions

protected string $context

The context to pass to the form widget.

protected Model $model

The initialized model used by the form.

protected array $modelsToSave

List of prepared models that require saving.

Show inhertied protected properties

Inherited protected properties

Public methods

public void __construct(Backend\Classes\Controller $controller)

Behavior constructor

Parameters

public void create(string $context=NULL)

Create Controller action

Parameters
  • string $context - Explicitly define a form context.

public mixed create_onSave($context=NULL)

Ajax handler for saving from the creation form.

Parameters
  • $context

public static void extendFormFields(callable $callback)

Static helper for extending form fields.

Parameters
  • callable $callback

public void formAfterCreate(Model $model)

Called after the creation form is saved.

Parameters
  • Model $model

public void formAfterDelete(Model $model)

Called after the form model is deleted.

Parameters
  • Model $model

public void formAfterSave(Model $model)

Called after the creation or updating form is saved.

Parameters
  • Model $model

public void formAfterUpdate(Model $model)

Called after the updating form is saved.

Parameters
  • Model $model

public void formBeforeCreate(Model $model)

Called before the creation form is saved.

Parameters
  • Model $model

public void formBeforeSave(Model $model)

Called before the creation or updating form is saved.

Parameters
  • Model $model

public void formBeforeUpdate(Model $model)

Called before the updating form is saved.

Parameters
  • Model $model

public Model formCreateModelObject()

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

public void formExtendFields(Backend\Widgets\Form $host, $fields)

Called after the form fields are defined.

Parameters

public void formExtendFieldsBefore(Backend\Widgets\Form $host)

Called before the form fields are defined.

Parameters

public Model formExtendModel(Model $model)

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

Parameters
  • Model $model

public void formExtendQuery(October\Rain\Database\Builder $query)

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

Parameters

public array formExtendRefreshData(Backend\Widgets\Form $host, array $saveData)

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

Parameters

public array formExtendRefreshFields(Backend\Widgets\Form $host, array $fields)

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

Parameters

public array formExtendRefreshResults(Backend\Widgets\Form $host, array $result)

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

Parameters

public Model formFindModelObject(string $recordId)

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

Parameters
  • string $recordId

public string formGetContext()

Returns the form context from the postback or configuration.

public string formGetId($suffix=NULL)

Helper to get a unique ID for the form widget.

Parameters
  • $suffix

public Model formGetModel()

Returns the model initialized by this form behavior.

public string formGetSessionKey($suffix=NULL)

Helper to get the form session key.

Parameters
  • $suffix

public Backend\Classes\WidgetBase formGetWidget()

Returns the widget used by this behavior.

public bool formHasOutsideFields()

Helper to check if a form tab has fields.

public bool formHasPrimaryTabs()

Helper to check if a form tab has fields.

public bool formHasSecondaryTabs()

Helper to check if a form tab has fields.

public string formRender(array $options=array())

Render the form.

Parameters
  • array $options - Custom options to pass to the form widget.

public string formRenderField(string $name)

Renders a single form field.

Parameters
  • string $name - Field name

public string formRenderOutsideFields()

Helper for custom layouts. Renders Outside Fields.

public string formRenderPreview()

Renders the form in preview mode.

public string formRenderPrimaryTabs()

Helper for custom layouts. Renders Primary Tabs.

public string formRenderSecondaryTabs()

Helper for custom layouts. Renders Secondary Tabs.

public void initForm(Model $model, $context=NULL)

Prepare the widgets used by this action

Parameters
  • Model $model
  • $context

public 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, update, delete
  • Model $model - The active model to parse in it's ID and attributes.

public void preview(int $recordId=NULL, string $context=NULL)

Preview Controller action

Parameters
  • int $recordId - The model primary key to preview.
  • string $context - Explicitly define a form context.

public void update(int $recordId=NULL, string $context=NULL)

Edit Controller action

Parameters
  • int $recordId - The model primary key to update.
  • string $context - Explicitly define a form context.

public mixed update_onDelete(int $recordId=NULL)

Ajax handler for deleting the record.

Parameters
  • int $recordId - The model primary key to delete.

public mixed update_onSave(int $recordId=NULL, $context=NULL)

Ajax handler for updating the form.

Parameters
  • int $recordId - The model primary key to update.
  • $context

Show inhertied pubilc methods

Inherited public methods

Protected methods

protected Model createModel()

Internal method, prepare the form model object

protected void deferPurgedSaveAttributes($model, $attributesToPurge)
Parameters
  • $model
  • $attributesToPurge

protected string getLang(string $name, string $default=NULL, array $extras=array())

Parses in some default variables to a language string defined in config.

Parameters
  • string $name - Configuration property containing the language string
  • string $default - A default language string to use if the config is not found
  • array $extras - Any extra params to include in the language string variables

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, update, delete.

protected array prepareModelsToSave(October\Rain\Database\Model $model, array $saveData)

Takes a model and fills it with data from a multidimensional array. 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

protected void prepareVars($model)

Prepares common form data

Parameters
  • $model

protected void setModelAttributes($model, $saveData)

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

Parameters
  • $model
  • $saveData

Show inhertied protected methods

Inherited protected methods