Backend\Widgets\Form

Extends:

Form Widget Used for building back end forms and renders a form.

Public properties

public array $fields

Form field configuration.

public array $tabs

Primary tab configuration.

public array $secondaryTabs

Secondary tab configuration.

public Model $model

Form model object.

public array $data

Dataset containing field values, if none supplied, model is used.

public string $context

The context of this form, fields that do not belong to this context will not be shown.

public string $arrayName

If the field element names should be contained in an array. Eg:

public bool $isNested

Used to flag that this form is being rendered as part of another form, a good indicator to expect that the form model and dataset values will differ.

public string $sessionKey

Active session key, used for editing forms and deferred bindings.

public bool $previewMode

Render this form with uneditable preview data.

Show inherited public properties

Inherited public properties

Protected properties

protected $defaultAlias

A unique alias to identify this widget.

protected boolean $fieldsDefined

Determines if field definitions have been created.

protected array $allFields

Collection of all fields used in this form. See also:

protected object $allTabs

Collection of tab sections used in this form. See also:

protected array $formWidgets

Collection of all form widgets used in this form.

protected Backend\Classes\WidgetManager $widgetManager

protected array $modelsToSave

List of prepared models that require saving.

Show inherited protected properties

Inherited protected properties

Public methods

public void addFields(array $fields, string $addToArea=NULL)

Programatically add fields, used internally and for extensibility.

Parameters
  • array $fields
  • string $addToArea

public void addSecondaryTabFields(array $fields)
Parameters
  • array $fields

public void addTabFields(array $fields)

Add tab fields.

Parameters
  • array $fields

public void bindToController()

Ensure fields are defined and form widgets are registered so they can also be bound to the controller this allows their AJAX features to operate.

public string getContext()

Returns the active context for displaying the form.

public void getField($field)

getField object specified

Parameters
  • $field

public void getFields()

getFields for the instance

public mixed getFormWidget(string $field)

Get a specified form widget

Parameters
  • string $field

public void getFormWidgets()

getFormWidgets for the instance

public array getSaveData()

Returns post data from a submitted form.

public Illuminate\Routing\Route|mixed|string getSessionKey()

Returns the active session key.

public mixed getTab(string $field)

Get a specified tab object. Options: outside, primary, secondary.

Parameters
  • string $field

public object[FormTabs] getTabs()

getTabs for the instance

public void init()

Initialize the widget, called by the constructor and free from its parameters.

public string nameToId($input $input)

Helper method to convert a field name to a valid ID attribute.

Parameters
  • $input $input

public array onLazyLoadTab()

Renders all fields of a tab in the target tab-pane.

public array onRefresh()

Event handler for refreshing the form.

public bool removeField(string $name)

Programatically remove a field.

Parameters
  • string $name

public bool removeTab(string $name)

Programatically remove all fields belonging to a tab.

Parameters
  • string $name

public string|bool render(array $options=array())

Renders the widget.

Options:

  • preview: Render this form as an uneditable preview. Default: false
  • useContainer: Wrap the result in a container, used by AJAX. Default: true
  • section: Which form section to render. Default: null
    • outside: Renders the Outside Fields section.
    • primary: Renders the Primary Tabs section.
    • secondary: Renders the Secondary Tabs section.
    • null: Renders all sections
Parameters
  • array $options

public string|bool renderField(string|array $field, array $options=array())

Renders a single form field

Options:

  • useContainer: Wrap the result in a container, used by AJAX. Default: true
Parameters
  • string|array $field - The field name or definition
  • array $options

public string|bool renderFieldElement(FormWidgetBase $field)

Renders the HTML element for a field

Parameters
  • FormWidgetBase $field

public array setFormValues(array $data=NULL)

Sets or resets form field values.

Parameters
  • array $data

Show inherited public methods

Inherited public methods

  • public void __call($name, $params) - defined in October\Rain\Extension\Extendable.
  • public static void __callStatic($name, $params) - defined in October\Rain\Extension\Extendable.
  • public void __construct(Backend\Classes\Controller $controller, array $configuration=array()) - defined in Backend\Classes\WidgetBase. Constructor.
  • public void __get($name) - defined in October\Rain\Extension\Extendable.
  • public void __set($name, $value) - defined in October\Rain\Extension\Extendable.
  • public void addCss($name, $attributes=array()) - defined in Backend\Classes\WidgetBase. addCss includes a StyleSheet asset to the asset list.
  • public void addCssBundle($name, $attributes=array()) - defined in Backend\Classes\WidgetBase. addCssBundle includes a CSS asset to the bundled combiner stream.
  • public void addDynamicMethod(string $dynamicName, callable $method, string $extension=NULL) - defined in October\Rain\Extension\Extendable. Programmatically adds a method to the extendable class.
  • public void addDynamicProperty(string $dynamicName, string $value=NULL) - defined in October\Rain\Extension\Extendable. Programmatically adds a property to the extendable class.
  • public void addJs($name, $attributes=array()) - defined in Backend\Classes\WidgetBase. addJs includes a JavaScript asset to the asset list.
  • public void addJsBundle($name, $attributes=array()) - defined in Backend\Classes\WidgetBase. addJsBundle includes a JS asset to the bundled combiner stream.
  • public void addRss($name, $attributes=array()) - defined in Backend\Classes\WidgetBase. addRss adds an RSS link asset to the asset list. Call $this->makeAssets().
  • public void addViewPath(string|array $path) - defined in Backend\Classes\WidgetBase. addViewPath prepends a path on the available view path locations.
  • public mixed asExtension(string $shortName) - defined in October\Rain\Extension\Extendable. Short hand for getClassExtension() method, except takes the short.
  • public self bindEvent($event, $callback, $priority=0) - defined in Backend\Classes\WidgetBase. Create a new event binding.
  • public self bindEventOnce($event, $callback) - defined in Backend\Classes\WidgetBase. Create a new event binding that fires once only.
  • public static void clearExtendedClasses() - defined in October\Rain\Extension\Extendable. Clear the list of extended classes so they will be re-extended.
  • public void combineAssets($assets, $localPath='') - defined in Backend\Classes\WidgetBase. combineAssets runs asset paths through the Asset Combiner.
  • public static void extend($callback) - defined in October\Rain\Extension\Extendable.
  • public void extendClassWith(string $extensionName) - defined in October\Rain\Extension\Extendable. Dynamically extend a class with a specified behavior.
  • public mixed extendableCall(string $name, array $params=NULL) - defined in October\Rain\Extension\Extendable. Magic method for __call().
  • public static mixed extendableCallStatic(string $name, array $params=NULL) - defined in October\Rain\Extension\Extendable. Magic method for __callStatic().
  • public void extendableConstruct() - defined in October\Rain\Extension\Extendable. extendableConstruct should be called as part of the constructor.
  • public static void extendableExtendCallback(callable $callback) - defined in October\Rain\Extension\Extendable. extendableExtendCallback is a helper method for ::extend() static method.
  • public string extendableGet(string $name) - defined in October\Rain\Extension\Extendable. Magic method for __get().
  • public string extendableSet(string $name, string $value) - defined in October\Rain\Extension\Extendable. Magic method for __set().
  • public array fireEvent(string $event, array $params=array(), boolean $halt=false) - defined in Backend\Classes\WidgetBase. Fire an event and call the listeners.
  • public mixed fireSystemEvent(string $event, array $params=array(), boolean $halt=true) - defined in Backend\Classes\WidgetBase. Fires a combination of local and global events. The first segment is removed.
  • public string fireViewEvent(string $event, array $params=array()) - defined in Backend\Classes\WidgetBase. Special event function used for extending within view files,
  • public void flushAssets() - defined in Backend\Classes\WidgetBase. Disables the use, and subequent broadcast, of assets. This is useful.
  • public string getAssetPath(string $fileName, string $assetPath=NULL) - defined in Backend\Classes\WidgetBase. Locates a file based on it's definition. If the file starts with.
  • public array getAssetPaths() - defined in Backend\Classes\WidgetBase. Returns an array of all registered asset paths.
  • public mixed getClassExtension(string $name) - defined in October\Rain\Extension\Extendable. Returns a behavior object from an extendable class, example:.
  • public array getClassMethods() - defined in October\Rain\Extension\Extendable. Get a list of class methods, extension equivalent of get_class_methods().
  • public string getConfig(string $name, string $default=NULL) - defined in Backend\Classes\WidgetBase. Safe accessor for configuration values.
  • public string getConfigPath(string $fileName, mixed $configPath=NULL) - defined in Backend\Classes\WidgetBase. Locates a file based on it's definition. If the file starts with.
  • public void getController() - defined in Backend\Classes\WidgetBase. Returns the controller using this widget.
  • public array getDynamicProperties() - defined in October\Rain\Extension\Extendable. Returns all dynamic properties and their values.
  • public string getEventHandler(string $name) - defined in Backend\Classes\WidgetBase. Returns a fully qualified event handler name for this widget.
  • public void getFatalError() - defined in Backend\Classes\WidgetBase. getFatalError returns error message.
  • public string getId(string $suffix=NULL) - defined in Backend\Classes\WidgetBase. Returns a unique ID for this widget. Useful in creating HTML markup.
  • public string getViewPath(string $fileName, mixed $viewPath=NULL) - defined in Backend\Classes\WidgetBase. getViewPath locates a file based on its definition. The file name can be prefixed.
  • public array getViewPaths() - defined in Backend\Classes\WidgetBase. getViewPaths returns the active view path locations.
  • public string guessConfigPath(string $suffix='') - defined in Backend\Classes\WidgetBase. Guess the package path for the called class.
  • public string guessConfigPathFrom(string $class, string $suffix='') - defined in Backend\Classes\WidgetBase. Guess the package path from a specified class.
  • public string guessViewPath(string $suffix='', bool $isPublic=false) - defined in Backend\Classes\WidgetBase. guessViewPath guesses the package path for the called class.
  • public string guessViewPathFrom(string $class, string $suffix='', bool $isPublic=false) - defined in Backend\Classes\WidgetBase. guessViewPathFrom guesses the package path from a specified class.
  • public void handleError($exception) - defined in Backend\Classes\WidgetBase. Sets standard page variables in the case of a controller error.
  • public void hasAssetsDefined() - defined in Backend\Classes\WidgetBase. hasAssetsDefined returns true if assets any have been added.
  • public boolean hasFatalError() - defined in Backend\Classes\WidgetBase. Determines whether a fatal error has been set or not.
  • public boolean isClassExtendedWith(string $name) - defined in October\Rain\Extension\Extendable. Check if extendable class is extended with a behavior object.
  • public string makeAssets(string $type=NULL) - defined in Backend\Classes\WidgetBase. Outputs <link> and <script> tags to load assets previously added with addJs and addCss method calls.
  • public object makeConfig(array $configFile=array(), array $requiredConfig=array()) - defined in Backend\Classes\WidgetBase. Reads the contents of the supplied file and applies it to this object.
  • public stdClass makeConfigFromArray(array $configArray=array()) - defined in Backend\Classes\WidgetBase. 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\WidgetBase. makeFileContents includes a file path using output buffering.
  • public Backend\Classes\FormWidgetBase makeFormWidget(string $class, mixed $fieldConfig=array(), array $widgetConfig=array()) - defined in Backend\Classes\WidgetBase. 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\WidgetBase. makeLayout renders a layout.
  • public string makeLayoutPartial(string $partial, array $params=array()) - defined in Backend\Classes\WidgetBase. makeLayoutPartial renders a layout partial.
  • public mixed makePartial(string $partial, array $params=array(), bool $throwException=true) - defined in Backend\Classes\WidgetBase. makePartial renders a partial file contents located in the views folder.
  • public string makeView(string $view) - defined in Backend\Classes\WidgetBase. makeView loads a view with the name specified. Applies layout if its name is provided.
  • public string makeViewContent(string $contents, string $layout=NULL) - defined in Backend\Classes\WidgetBase. makeViewContent renders supplied contents inside a layout.
  • public Backend\Classes\WidgetBase makeWidget(string $class, array $widgetConfig=array()) - defined in Backend\Classes\WidgetBase. Makes a widget object with the supplied configuration file.
  • public stdClass mergeConfig(mixed $configA, mixed $configB) - defined in Backend\Classes\WidgetBase. Merges two configuration sources, either prepared or not, and returns.
  • public boolean methodExists(string $name) - defined in October\Rain\Extension\Extendable. Checks if a method exists, extension equivalent of method_exists().
  • public boolean propertyExists(string $name) - defined in October\Rain\Extension\Extendable. Checks if a property exists, extension equivalent of property_exists().
  • public void resetSession() - defined in Backend\Classes\WidgetBase. Resets all session data related to this widget.
  • public self unbindEvent(string $event=NULL) - defined in Backend\Classes\WidgetBase. Destroys an event binding.

Protected methods

protected void applyFiltersFromModel()

applyFiltersFromModel allows the model to filter fields

protected array|null dataArrayGet(array $array, array $parts, null $default=NULL)

Variant to array_get() but preserves dots in key names.

Parameters
  • array $array
  • array $parts
  • null $default

protected array dataArraySet(array &$array, array $parts, string $value)

Variant to array_set() but preserves dots in key names.

Parameters
  • array &$array
  • array $parts
  • string $value

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

protected void defineFormFields()

Creates a flat array of form fields from the configuration. Also slots fields in to their respective tabs.

protected void getFieldDepends(Backend\Classes\FormField $field)

getFieldDepends returns a HTML encoded value containing the other fields this field depends on

Parameters

protected array getFieldName(string $field)

Parses a field's name

Parameters
  • string $field - Field name

protected string getFieldValue(mixed $field)

Looks up the field value.

Parameters
  • mixed $field

protected void isFormWidget($fieldType)

isFormWidget checks if a field type is a widget or not

Parameters
  • $fieldType

protected void loadAssets()

Adds widget specific asset files. Use $this->addJs() and $this->addCss() to register new assets to include on the page.

protected FormField makeFormField(string $name, array $config=array())

Creates a form field object from name and configuration.

Parameters
  • string $name
  • array $config

protected Backend\Traits\FormWidgetBase|null makeFormFieldWidget($field $field)

Makes a widget object from a form field object.

Parameters
  • $field $field

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()

Prepares the form data

protected void processAutoSpan($fields)

Converts fields with a span set to 'auto' as either 'left' or 'right' depending on the previous field.

Parameters
  • $fields

protected void setModelAttributes(October\Rain\Database\Model $model, array $saveData, $attrName='')

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

Parameters

protected boolean showFieldLabels(Backend\Classes\FormField $field)

Helper method to determine if field should be rendered with label and comments.

Parameters

protected void useDefaultValues()

useDefaultValues checks if default values should be taken from data

protected mixed validateModel()

Validate the supplied form model.

Show inherited protected methods

Inherited protected methods

  • protected void combineBundledAssets($type) - defined in Backend\Classes\WidgetBase. combineBundledAssets spins over every bundle definition and combines them to an asset.
  • protected array emitterEventSortEvents(string $eventName) - defined in Backend\Classes\WidgetBase. Sort the listeners for a given event by priority.
  • protected boolean extendableIsAccessible(mixed $class, string $propertyName) - defined in October\Rain\Extension\Extendable. Checks if a property is accessible, property equivalent of is_callable().
  • protected void extensionExtractMethods(string $extensionName, object $extensionObject) - defined in October\Rain\Extension\Extendable. Extracts the available methods from a behavior and adds it to the.
  • protected void fillFromConfig(array $properties=NULL) - defined in Backend\Classes\WidgetBase. Transfers config values stored inside the $config property directly.
  • protected string getAssetEntryBuildPath(array $asset) - defined in Backend\Classes\WidgetBase. Internal helper, attaches a build code to an asset path.
  • protected string getAssetScheme(string $asset) - defined in Backend\Classes\WidgetBase. Internal helper, get asset scheme.
  • protected void getLocalPath($relativePath) - defined in Backend\Classes\WidgetBase. getLocalPath converts a relative path to a local path.
  • protected string getSession(string $key=NULL, string $default=NULL) - defined in Backend\Classes\WidgetBase. Retrieves a widget related key/value pair from session data.
  • protected void handleViewException($e, $obLevel) - defined in Backend\Classes\WidgetBase. handleViewException handles a view exception.
  • protected string makeSessionId() - defined in Backend\Classes\WidgetBase. Returns a unique session identifier for this widget and controller action.
  • protected void putSession(string $key, string $value) - defined in Backend\Classes\WidgetBase. Saves a widget related key/value pair in to session data.
  • protected void removeDuplicates() - defined in Backend\Classes\WidgetBase. Removes duplicate assets from the entire collection.
  • protected void renderAssetAttributes($type, $asset) - defined in Backend\Classes\WidgetBase. renderAssetAttributes takes an asset definition and returns the necessary HTML output.