-
Backend
-
Behaviors
-
Classes
-
Controllers
-
Database
-
Seeds
-
-
Facades
-
FormWidgets
-
Helpers
-
Exception
- Backend
-
-
Models
-
ReportWidgets
-
Skins
-
Traits
-
Widgets
- ServiceProvider
-
-
Cms
-
Classes
- Asset
- AutoDatasource
- CmsCompoundObject
- CmsController
- CmsException
- CmsObject
- CmsObjectCollection
- CodeBase
- CodeParser
- ComponentBase
- ComponentHelpers
- ComponentManager
- ComponentPartial
- Content
- Controller
- Layout
- LayoutCode
- MediaLibrary
- MediaLibraryItem
- MediaViewHelper
- Meta
- ObjectMemoryCache
- Page
- PageCode
- Partial
- PartialCode
- PartialStack
- Router
- Theme
- ThemeManager
-
Components
-
Contracts
-
Controllers
-
Facades
-
FormWidgets
-
Helpers
-
Models
-
ReportWidgets
-
Traits
-
Twig
- ComponentNode
- ComponentTokenParser
- ContentNode
- ContentTokenParser
- DebugExtension
- DefaultNode
- DefaultTokenParser
- Extension
- FlashNode
- FlashTokenParser
- FrameworkNode
- FrameworkTokenParser
- Loader
- PageNode
- PageTokenParser
- PartialNode
- PartialTokenParser
- PlaceholderNode
- PlaceholderTokenParser
- PutNode
- PutTokenParser
- ScriptsNode
- ScriptsTokenParser
- StylesNode
- StylesTokenParser
-
Widgets
- ServiceProvider
-
-
System
-
Behaviors
-
Classes
-
Console
-
Controllers
-
Database
-
Helpers
-
Models
-
ReportWidgets
-
Traits
-
Twig
- ServiceProvider
-
-
Events
-
backend
-
ajax
-
filter
-
form
-
list
-
menu
-
page
-
user
-
-
cms
-
ajax
-
block
-
combiner
-
component
-
object
-
page
-
router
-
template
-
theme
-
-
halcyon
-
datasource
-
-
mailer
-
media
-
model
-
system
-
assets
-
console
-
mirror
-
theme
-
-
reportwidgets
-
settings
- extendConfigFile
-
-
translator
-
-
Library
-
Argon
-
Auth
-
Models
- AuthException
- Manager
-
-
Config
-
Cookie
-
Middleware
-
-
Database
-
Attach
-
Behaviors
-
Concerns
-
Connections
-
Connectors
-
Models
-
Relations
-
Schema
-
Traits
-
Updates
- README
- Builder
- Collection
- DatabaseServiceProvider
- DataFeed
- Dongle
- MemoryCache
- Model
- ModelBehavior
- ModelException
- NestedTreeScope
- Pivot
- QueryBuilder
- SortableScope
- TreeCollection
- Updater
-
-
Events
-
Exception
-
Extension
-
Filesystem
-
Flash
-
Foundation
-
Bootstrap
-
Console
-
Exception
-
Http
-
Middleware
- Kernel
-
-
Providers
- Application
- Maker
-
-
Halcyon
-
Datasource
-
Exception
-
Processors
-
Traits
- README
- Builder
- Collection
- HalcyonServiceProvider
- MemoryCacheManager
- MemoryRepository
- Model
-
-
Html
-
Mail
-
Network
-
Parse
-
Router
-
Scaffold
-
Support
-
Translation
-
- Documentation
- API
- Backend
- Behaviors
- FormController
Backend\Behaviors\FormController
Source: ~/modules/backend/behaviors/FormController.php
Extends:
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.
See also:
Public properties
There are no public properties in the class.
Show inherited public properties
Inherited public properties
- public static string $extendableStaticCalledClass - defined in October\Rain\Extension\ExtensionBase. The calling class when using a static method.
- public string $assetPath - defined in Backend\Classes\ControllerBehavior. Specifies a path to the asset directory.
- public array $vars - defined in Backend\Classes\ControllerBehavior. A list of variables to pass to the page.
- public string $layout - defined in Backend\Classes\ControllerBehavior. Layout to use for the view.
- public bool $suppressLayout - defined in Backend\Classes\ControllerBehavior. Prevents the use of a layout.
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 array $actions
Visible actions in context of the controller
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 inherited protected properties
Inherited protected properties
- protected array $config - defined in Backend\Classes\ControllerBehavior. Supplied configuration.
- protected static array $extensionCallbacks - defined in October\Rain\Extension\ExtensionBase. Used to extend the constructor of an extension class.
- protected $extensionHidden - defined in October\Rain\Extension\ExtensionBase.
- protected array $assets - defined in Backend\Classes\ControllerBehavior. Collection of assets to display in the layout.
- protected string $configPath - defined in Backend\Classes\ControllerBehavior. Specifies a path to the config directory.
- protected string|array $viewPath - defined in Backend\Classes\ControllerBehavior. Specifies a path to the views directory.
- protected string $layoutPath - defined in Backend\Classes\ControllerBehavior. Specifies a path to the layout directory.
Public methods
public void __construct(Backend\Classes\Controller $controller)
Behavior constructor
Parameters
- Backend\Classes\Controller $controller
public void create(string $context=NULL)
Controller "create" action used for creating new model records.
Parameters
- string $context - Form context
public mixed create_onSave(string $context=NULL)
AJAX handler "onSave" called from the create action and primarily used for creating new records.
This handler will invoke the unique controller overrides
formBeforeCreate
and formAfterCreate
.
Parameters
- string $context - Form 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, array $fields)
Called after the form fields are defined.
Parameters
- Backend\Widgets\Form $host - The hosting form widget
- array $fields - Array of all defined form field objects (\Backend\Classes\FormField)
public void formExtendFieldsBefore(Backend\Widgets\Form $host)
Called before the form fields are defined.
Parameters
- Backend\Widgets\Form $host - The hosting form widget
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
- Backend\Widgets\Form $host - The hosting form widget
- array $saveData - Current save data
public array formExtendRefreshFields(Backend\Widgets\Form $host, array $fields)
Called when the form is refreshed, giving the opportunity to modify the form fields.
Parameters
- Backend\Widgets\Form $host - The hosting form widget
- array $fields - Current form fields
public array formExtendRefreshResults(Backend\Widgets\Form $host, array $result)
Called after the form is refreshed, should return an array of additional result parameters.
Parameters
- Backend\Widgets\Form $host - The hosting form widget
- array $result - Current result 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 active form context, either obtained from the postback
variable called form_context
or detected from the configuration,
or routing parameters.
public string formGetId(string $suffix=NULL)
Returns a unique ID for the form widget used by this behavior. 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
- string $suffix
public October\Rain\Database\Model formGetModel()
Returns the model initialized by this form behavior.
The model will be provided by one of the page actions or AJAX
handlers via the initForm
method.
public string formGetSessionKey()
Helper to get the form session key.
public Backend\Widgets\Form formGetWidget()
Returns the form widget used by this behavior.
public bool formHasOutsideFields()
View helper to check if a form tab has fields in the non-tabbed section (outside fields).
<?php if ($this->formHasOutsideFields()): ?> <!-- Do something --> <?php endif ?>
public bool formHasPrimaryTabs()
View helper to check if a form tab has fields in the primary tab section.
<?php if ($this->formHasPrimaryTabs()): ?> <!-- Do something --> <?php endif ?>
public bool formHasSecondaryTabs()
View helper to check if a form tab has fields in the secondary tab section.
<?php if ($this->formHasSecondaryTabs()): ?> <!-- Do something --> <?php endif ?>
public string formRender(array $options=array())
Method to render the prepared form markup. This method is usually called from a view file.
<?= $this->formRender() ?>
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']) ?>
See also:
Parameters
- array $options - Render options
public string formRenderField(string $name, array $options=array())
View helper to render a single form field.
<?= $this->formRenderField('field_name') ?>
Parameters
- string $name - Field name
- array $options - (e.g. ['useContainer'=>false])
public string formRenderOutsideFields()
View helper to render the form fields belonging to the non-tabbed section (outside form fields).
<?= $this->formRenderOutsideFields() ?>
public string formRenderPreview()
View helper to render the form in preview mode.
<?= $this->formRenderPreview() ?>
public string formRenderPrimaryTabs()
View helper to render the form fields belonging to the primary tabs section.
<?= $this->formRenderPrimaryTabs() ?>
public string formRenderSecondaryTabs()
View helper to render the form fields belonging to the secondary tabs section.
<?= $this->formRenderPrimaryTabs() ?>
public void initForm(October\Rain\Database\Model $model, string $context=NULL)
Initialize the form configuration against a model and context value.
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.
See also:
Parameters
- October\Rain\Database\Model $model
- string $context - Form 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)
Controller "preview" action used for viewing existing model records. This action takes a record identifier (primary key of the model) to locate the record used for sourcing the existing preview data.
Parameters
- int $recordId - Record identifier
- string $context - Form context
public void update(int $recordId=NULL, string $context=NULL)
Controller "update" action used for updating existing model records. This action takes a record identifier (primary key of the model) to locate the record used for sourcing the existing form values.
Parameters
- int $recordId - Record identifier
- string $context - Form context
public mixed update_onDelete(int $recordId=NULL)
AJAX handler "onDelete" called from the update action and used for deleting existing records.
This handler will invoke the unique controller override
formAfterDelete
.
Parameters
- int $recordId - Record identifier
public mixed update_onSave(int $recordId=NULL, string $context=NULL)
AJAX handler "onSave" called from the update action and primarily used for updating existing records.
This handler will invoke the unique controller overrides
formBeforeUpdate
and formAfterUpdate
.
Parameters
- int $recordId - Record identifier
- string $context - Form context
Inherited public methods
- public void addCss(string $name, array $attributes=array()) - defined in Backend\Classes\ControllerBehavior. Adds StyleSheet asset to the asset list. Call $this->makeAssets() in a view.
- public void addJs(string $name, array $attributes=array()) - defined in Backend\Classes\ControllerBehavior. Adds JavaScript asset to the asset list. Call $this->makeAssets() in a view.
- public void addRss(string $name, array $attributes=array()) - defined in Backend\Classes\ControllerBehavior. Adds an RSS link asset to the asset list. Call $this->makeAssets() in a view.
- public void addViewPath(string|array $path) - defined in Backend\Classes\ControllerBehavior. Prepends a path on the available view path locations.
- public string combineAssets(array $assets, string $localPath='') - defined in Backend\Classes\ControllerBehavior. Run the provided assets through the Asset Combiner.
- public static void extend($callback) - defined in October\Rain\Extension\ExtensionBase.
- public void extensionApplyInitCallbacks() - defined in October\Rain\Extension\ExtensionBase.
- public static void extensionExtendCallback(callable $callback) - defined in October\Rain\Extension\ExtensionBase. Helper method for
::extend()
static method. - public void extensionIsHiddenField($name) - defined in October\Rain\Extension\ExtensionBase.
- public void extensionIsHiddenMethod($name) - defined in October\Rain\Extension\ExtensionBase.
- public void flushAssets() - defined in Backend\Classes\ControllerBehavior. Disables the use, and subequent broadcast, of assets. This is useful.
- public string getAssetPath(string $fileName, string $assetPath=NULL) - defined in Backend\Classes\ControllerBehavior. Locates a file based on it's definition. If the file starts with.
- public array getAssetPaths() - defined in Backend\Classes\ControllerBehavior. Returns an array of all registered asset paths.
- public static void getCalledExtensionClass() - defined in October\Rain\Extension\ExtensionBase.
- public string getConfig(string $name=NULL, mixed $default=NULL) - defined in Backend\Classes\ControllerBehavior. Safe accessor for configuration values.
- public string getConfigPath(string $fileName, mixed $configPath=NULL) - defined in Backend\Classes\ControllerBehavior. Locates a file based on it's definition. If the file starts with.
- public string getViewPath(string $fileName, mixed $viewPath=NULL) - defined in Backend\Classes\ControllerBehavior. Locates a file based on its definition. The file name can be prefixed with a.
- public array getViewPaths() - defined in Backend\Classes\ControllerBehavior. Returns the active view path locations.
- public string guessConfigPath(string $suffix='') - defined in Backend\Classes\ControllerBehavior. Guess the package path for the called class.
- public string guessConfigPathFrom(string $class, string $suffix='') - defined in Backend\Classes\ControllerBehavior. Guess the package path from a specified class.
- public string guessViewPath(string $suffix='', bool $isPublic=false) - defined in Backend\Classes\ControllerBehavior. Guess the package path for the called class.
- public string guessViewPathFrom(string $class, string $suffix='', bool $isPublic=false) - defined in Backend\Classes\ControllerBehavior. Guess the package path from a specified class.
- public bool hasAssetsDefined() - defined in Backend\Classes\ControllerBehavior. Returns true if assets any have been added.
- public string localMakeFileContents(string $filePath, array $extraParams=array()) - defined in Backend\Classes\ControllerBehavior. Includes a file path using output buffering.
- public string makeAssets(string $type=NULL) - defined in Backend\Classes\ControllerBehavior. Outputs
<link>
and<script>
tags to load assets previously added with addJs and addCss method calls. - public array|stdClass makeConfig(array $configFile=array(), array $requiredConfig=array()) - defined in Backend\Classes\ControllerBehavior. Reads the contents of the supplied file and applies it to this object.
- public stdClass makeConfigFromArray(array $configArray=array()) - defined in Backend\Classes\ControllerBehavior. Makes a config object from an array, making the first level keys properties of a new object.
- public string makeFileContents(string $filePath, array $extraParams=array()) - defined in Backend\Classes\ControllerBehavior. Makes all views in context of the controller, not the behavior.
- public Backend\Classes\FormWidgetBase makeFormWidget(string $class, mixed $fieldConfig=array(), array $widgetConfig=array()) - defined in Backend\Classes\ControllerBehavior. Makes a form widget object with the supplied form field and widget configuration.
- public mixed makeLayout(string $name=NULL, array $params=array(), bool $throwException=true) - defined in Backend\Classes\ControllerBehavior. Render a layout.
- public string makeLayoutPartial(string $partial, array $params=array()) - defined in Backend\Classes\ControllerBehavior. Renders a layout partial.
- public mixed makePartial(string $partial, array $params=array(), bool $throwException=true) - defined in Backend\Classes\ControllerBehavior. Render a partial file contents located in the views folder.
- public string makeView(string $view) - defined in Backend\Classes\ControllerBehavior. Loads a view with the name specified. Applies layout if its name is provided by the parent object.
- public string makeViewContent(string $contents, string $layout=NULL) - defined in Backend\Classes\ControllerBehavior. Renders supplied contents inside a layout.
- public Backend\Classes\WidgetBase makeWidget(string $class, array $widgetConfig=array()) - defined in Backend\Classes\ControllerBehavior. Makes a widget object with the supplied configuration file.
- public stdClass mergeConfig(mixed $configA, mixed $configB) - defined in Backend\Classes\ControllerBehavior. Merges two configuration sources, either prepared or not, and returns.
- public void resetSession() - defined in Backend\Classes\ControllerBehavior. Resets all session data related to this widget.
- public void setConfig(mixed $config, array $required=array()) - defined in Backend\Classes\ControllerBehavior. Sets the configuration values.
Protected methods
protected October\Rain\Database\Model createModel()
Internal method used to prepare the form model object.
protected void deferPurgedSaveAttributes(October\Rain\Database\Model $model, array $attributesToPurge)
Removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.
Parameters
- October\Rain\Database\Model $model - Model to adjust.
- array $attributesToPurge - Attribute values to remove from the model.
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 that 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
- October\Rain\Database\Model $model - Model to fill.
- array $saveData - Attribute values to fill model.
protected void prepareVars(October\Rain\Database\Model $model)
Prepares commonly used view data.
Parameters
- October\Rain\Database\Model $model
protected void setModelAttributes(October\Rain\Database\Model $model, array $saveData)
Sets a data collection to a model attributes, relations are also set.
Parameters
- October\Rain\Database\Model $model - Model to fill.
- array $saveData - Attribute values to fill model.
Show inherited protected methods
Inherited protected methods
- protected void addAsset(string $type, string $path, array $attributes) - defined in Backend\Classes\ControllerBehavior. Adds the provided asset to the internal asset collections.
- protected bool controllerMethodExists(string $methodName) - defined in Backend\Classes\ControllerBehavior. Returns true in case if a specified method exists in the extended controller.
- protected void extensionHideField($name) - defined in October\Rain\Extension\ExtensionBase.
- protected void extensionHideMethod($name) - defined in October\Rain\Extension\ExtensionBase.
- protected string getAssetEntryBuildPath(array $asset) - defined in Backend\Classes\ControllerBehavior. Internal helper, attaches a build code to an asset path.
- protected string getAssetScheme(string $asset) - defined in Backend\Classes\ControllerBehavior. Internal helper, get asset scheme.
- protected void getLocalPath($relativePath) - defined in Backend\Classes\ControllerBehavior.
- protected string getSession(string $key=NULL, string $default=NULL) - defined in Backend\Classes\ControllerBehavior. Retrieves a widget related key/value pair from session data.
- protected void handleViewException(Exception $e, int $obLevel) - defined in Backend\Classes\ControllerBehavior. Handle a view exception.
- protected void hideAction(mixed $methodName) - defined in Backend\Classes\ControllerBehavior. Protects a public method from being available as an controller action.
- protected string makeSessionId() - defined in Backend\Classes\ControllerBehavior. Returns a unique session identifier for this widget and controller action.
- protected void putSession(string $key, string $value) - defined in Backend\Classes\ControllerBehavior. Saves a widget related key/value pair in to session data.
- protected void removeDuplicates() - defined in Backend\Classes\ControllerBehavior. Removes duplicate assets from the entire collection.