Contents

Backend\FormWidgets\Relation

Overview

Relation renders a field pre-populated with a belongsTo and belongsToHasMany relation

Extends
Implements
  • Larajax\Contracts\ViewComponentInterface

Public Properties

public bool $readOnly

readOnly if the sensitive field cannot be edited, but can be toggled

public string $nameFrom

nameFrom is the model column to use for the name reference

public string $sqlSelect

sqlSelect is the custom SQL column selection to use for the name reference

public string $emptyOption

emptyOption to use if the relation is singular (belongsTo)

public string $modelScope

modelScope method for the list query.

public string $conditions

conditions filters the relation using a raw where query statement.

public mixed $defaultSort

defaultSort column to look for.

public mixed $excludeFrom

excludeFrom identifiers from the specified model attribute.

public bool $useController

useController to completely replace this widget the RelationController behavior.

public array $useControllerConfig

useControllerConfig manually configures the RelationController behavior.

public FormField $renderFormField

renderFormField object used for rendering a simple field type

public mixed $quickCreate

quickCreate config for the quick create feature

Show inherited public properties

Inherited Public Properties

Protected Properties

protected $defaultAlias

defaultAlias to identify this widget.

protected array $modelsToSave

modelsToSave are models that require saving

protected array $quickCreateConfig

quickCreateConfig resolved configuration

protected FormWidget|null $quickCreateFormWidget

Show inherited protected properties

Inherited Protected Properties


Public Methods

public bindToController()

public bindToController(): void

bindToController ensures manual relation controller configuration is applied.

public getSaveValue()

public getSaveValue($value): void

getSaveValue processes the postback value for this widget. If the value is omitted from postback data, the form widget will be skipped.

public hasQuickCreate()

public hasQuickCreate(): bool 

hasQuickCreate returns true if quick create should be active

public init()

public init(): void

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

public nearestModelAttribute()

public nearestModelAttribute($attribute): void

public onLoadQuickCreateForm()

public onLoadQuickCreateForm(): void

onLoadQuickCreateForm AJAX handler to render the popup form

public onQuickCreateRecord()

public onQuickCreateRecord(): void

onQuickCreateRecord AJAX handler to create the new record

public prepareVars()

public prepareVars(): void

prepareVars for display

public render()

public render(): void

render the widget's primary contents.

public resetFormValue()

public resetFormValue(): void

resetFormValue from the form field

public resolveModelAttribute()

public resolveModelAttribute(string $attribute): array 

Returns the final model and attribute name of a nested HTML array attribute. Eg: [$model, $attribute] = $this->resolveModelAttribute($this->valueFrom);

Show inherited public methods

Inherited Public Methods

Protected Methods

protected addQuickCreateOption()

protected addQuickCreateOption($options): void

addQuickCreateOption prepends the quick create sentinel option to the dropdown

protected applyDefaultSortToQuery()

protected applyDefaultSortToQuery($query): void

protected applyQuickCreateFieldDefaults()

protected applyQuickCreateFieldDefaults($field): void

applyQuickCreateFieldDefaults ensures an empty option exists so the quick create option is never selected by default when no entries are available

protected deferPurgedSaveAttributes()

protected deferPurgedSaveAttributes(
    October\Rain\Database\Model $model,
    array $attributesToPurge
): void 

deferPurgedSaveAttributes removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.

protected defineRelationControllerConfig()

protected defineRelationControllerConfig(): void

protected evalUseController()

protected evalUseController($defaultPref): bool 

evalUseController determines if the relation controller is usable and returns the default preference if it can be used.

protected getRelationControllerFieldName()

protected getRelationControllerFieldName(): void

protected getRelationModel()

protected getRelationModel(): Relation 

Returns the model of a relation type, supports nesting via HTML array.

protected getRelationObject()

protected getRelationObject(): Relation 

Returns the value as a relation object from the model, supports nesting via HTML array.

protected getRelationType()

protected getRelationType(): string 

getRelationType returns the value as a relation type from the model, supports nesting via HTML array.

protected initQuickCreate()

protected initQuickCreate(): void

initQuickCreate parses the quickCreate config and prepares the form widget when processing a quick create request.

protected isRelationTypeSingular()

protected isRelationTypeSingular(): bool 

isRelationTypeSingular checks if the related model is singular.

protected loadAssets()

protected loadAssets(): void

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

protected loadQuickCreateAssets()

protected loadQuickCreateAssets(): void

loadQuickCreateAssets loads the JS control for quick create

protected makeFieldOptionsForTree()

protected makeFieldOptionsForTree($items, $nameFrom, $primaryKeyName): void

protected makeQuickCreateFormWidget()

protected makeQuickCreateFormWidget(): void

makeQuickCreateFormWidget creates the form widget for the popup

protected makeRenderFormField()

protected makeRenderFormField(): void

makeRenderFormField for rendering a simple field type

protected performSaveOnModel()

protected performSaveOnModel($model, $data, $options = null): void

performSaveOnModel saves complex data against a model inside a database transaction.

protected prepareModelsToSave()

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

prepareModelsToSave 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();
}

protected setModelAttributes()

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

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

Show inherited protected methods

Inherited Protected Methods