-
Docs
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
- RelationController
Backend\Behaviors\RelationController
Source: ~/modules/backend/behaviors/RelationController.php
Extends:
Uses a combination of lists and forms for managing Model relations.
This behavior is implemented in the controller like so:
public $implement = [ 'Backend.Behaviors.RelationController', ]; public $relationConfig = 'config_relation.yaml';
The $relationConfig
property makes reference to the configuration
values as either a YAML file, located in the controller view directory,
or directly as a PHP array.
Public properties
public string $relationType
Relationship type
public string $relationName
Relationship name
public Model $relationModel
Relationship model
public Model $relationObject
Relationship object
public string $sessionKey
Active session key, used for deferred bindings.
public bool $readOnly
Disables the ability to add, update, delete or create relations.
public bool $deferredBinding
Defers all binding actions using a session key when it is available.
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\Widgets\Search $searchWidget
Reference to the search widget object.
protected Backend\Widgets\Toolbar $toolbarWidget
Reference to the toolbar widget object.
protected Backend\Classes\WidgetBase $viewWidget
Reference to the widget used for viewing (list or form).
protected Backend\Widgets\Filter $viewFilterWidget
Reference to the view filter widget.
protected Backend\Classes\WidgetBase $manageWidget
Reference to the widget used for relation management.
protected Backend\Widgets\Filter $manageFilterWidget
Reference to the manage filter widget.
protected Backend\Classes\WidgetBase $pivotWidget
Reference to widget for relations with pivot data.
protected $requiredProperties
Properties that must exist in the controller using this behavior.
protected array $requiredRelationProperties
Properties that must exist for each relationship definition.
protected array $requiredConfig
Configuration values that must exist when applying the primary config file.
protected array $actions
Visible actions in context of the controller
protected array $originalConfig
Original configuration values
protected array $extraConfig
Config provided by the relationRender method
protected bool $initialized
Has the behavior been initialized.
protected Model $model
The parent model of the relationship.
protected Model $field
The relationship field as defined in the configuration.
protected string $alias
A unique alias to pass to widgets.
protected array $toolbarButtons
The set of buttons to display in view mode.
protected Model $viewModel
Reference to the model used for viewing (form only).
protected string $viewMode
Relation has many (multi) or has one (single).
protected string $manageTitle
The title used for the manage popup.
protected string $manageMode
Management of relation as list, form, or pivot.
protected string $forceViewMode
Force a certain view mode.
protected string $forceManageMode
Force a certain manage mode.
protected string $eventTarget
The target that triggered an AJAX event (button, list)
protected int $manageId
Primary id of an existing relation record.
protected int $foreignId
Foeign id of a selected pivot record.
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 Backend\Classes\Controller $controller - defined in Backend\Classes\ControllerBehavior. Reference to the back end controller.
- 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 initRelation(Model $model, string $field=NULL)
Prepare the widgets used by this behavior
Parameters
- Model $model
- string $field
public void onRelationButtonAdd()
public void onRelationButtonCreate()
public void onRelationButtonDelete()
public void onRelationButtonLink()
public void onRelationButtonRemove()
public void onRelationButtonUnlink()
public void onRelationButtonUpdate()
public void onRelationClickManageList()
public void onRelationClickManageListPivot()
public void onRelationClickViewList()
public void onRelationManageAdd()
Add an existing related model to the primary model
public void onRelationManageAddPivot()
Add multiple items using a single pivot form.
public void onRelationManageCreate()
Create a new related model
public void onRelationManageDelete()
Delete an existing related model completely
public void onRelationManageForm()
public void onRelationManagePivotCreate()
public void onRelationManagePivotForm()
public void onRelationManagePivotUpdate()
public void onRelationManageRemove()
Remove an existing related model from the primary model
public void onRelationManageUpdate()
Updated an existing related model's fields
public void prepareVars()
Prepares the view data.
public void relationExtendConfig(object $config, string $field, October\Rain\Database\Model $model)
Provides an opportunity to manipulate the field configuration.
Parameters
- object $config
- string $field
- October\Rain\Database\Model $model
public void relationExtendManageFilterWidget(Backend\Widgets\Filter $widget, string $field, October\Rain\Database\Model $model)
Provides an opportunity to manipulate the manage filter widget.
Parameters
- Backend\Widgets\Filter $widget
- string $field
- October\Rain\Database\Model $model
public void relationExtendManageWidget(Backend\Classes\WidgetBase $widget, string $field, October\Rain\Database\Model $model)
Provides an opportunity to manipulate the manage widget.
Parameters
- Backend\Classes\WidgetBase $widget
- string $field
- October\Rain\Database\Model $model
public void relationExtendPivotWidget(Backend\Classes\WidgetBase $widget, string $field, October\Rain\Database\Model $model)
Provides an opportunity to manipulate the pivot widget.
Parameters
- Backend\Classes\WidgetBase $widget
- string $field
- October\Rain\Database\Model $model
public array relationExtendRefreshResults(string $field)
The view widget is often refreshed when the manage widget makes a change, you can use this method to inject additional containers when this process occurs. Return an array with the extra values to send to the browser, eg:
return ['#myCounter' => 'Total records: 6'];
Parameters
- string $field
public void relationExtendViewFilterWidget(Backend\Widgets\Filter $widget, string $field, October\Rain\Database\Model $model)
Provides an opportunity to manipulate the view filter widget.
Parameters
- Backend\Widgets\Filter $widget
- string $field
- October\Rain\Database\Model $model
public void relationExtendViewWidget(Backend\Classes\WidgetBase $widget, string $field, October\Rain\Database\Model $model)
Provides an opportunity to manipulate the view widget.
Parameters
- Backend\Classes\WidgetBase $widget
- string $field
- October\Rain\Database\Model $model
public string relationGetId(string $suffix=NULL)
Returns a unique ID for this relation and field combination.
Parameters
- string $suffix - A suffix to use with the identifier.
public Backend\Classes\WidgetBase relationGetManageWidget()
Returns the manage widget used by this behavior.
public void relationGetSessionKey($force=false)
Returns the active session key.
Parameters
- $force
public Backend\Classes\WidgetBase relationGetViewWidget()
Returns the view widget used by this behavior.
public string relationMakePartial(string $partial, array $params=array())
Controller accessor for making partials within this behavior.
Parameters
- string $partial
- array $params
public array relationRefresh(string $field=NULL)
Refreshes the relation container only, useful for returning in custom AJAX requests.
Parameters
- string $field - Relation definition.
public string relationRender(string $field, array $options=array())
Renders the relationship manager.
Parameters
- string $field - The relationship field.
- array $options
public string relationRenderToolbar(string $field=NULL)
Renders the toolbar only.
Parameters
- string $field - The relationship field.
public string relationRenderView(string $field=NULL)
Renders the view only.
Parameters
- string $field - The relationship field.
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 void applyExtraConfig($config, $field=NULL)
Apply extra configuration
Parameters
- $config
- $field
protected void beforeAjax()
The controller action is responsible for supplying the parent model so it's action must be fired. Additionally, each AJAX request must supply the relation's field name (_relation_field).
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 void evalFormContext($mode='manage', $exists=false)
Determine supplied form context.
Parameters
- $mode
- $exists
protected string evalManageMode()
Determine the management mode based on the relation type and settings.
protected string evalManageTitle()
Determine the management mode popup title.
protected string evalToolbarButtons()
Determine the default buttons based on the model relationship type.
protected string evalViewMode()
Determine the view mode based on the model relationship type.
protected void findExistingRelationIds($checkIds=NULL)
Returns the existing record IDs for the relation.
Parameters
- $checkIds
protected void makeConfigForMode($mode='view', $type='list', $throwException=true)
Returns the configuration for a mode (view, manage, pivot) for an expected type (list, form). Uses fallback configuration.
Parameters
- $mode
- $type
- $throwException
protected Backend\Classes\WidgetBase|null makeFilterWidget($type $type)
Initialize a filter widget
Parameters
- $type $type - String Either 'manage' or 'view'
protected void makeManageWidget()
protected void makePivotWidget()
protected void makeSearchWidget()
protected void makeToolbarWidget()
protected void makeViewWidget()
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 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.
protected string validateField(string $field=NULL)
Validates the supplied field and initializes the relation manager.
Parameters
- string $field - The relationship field.
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.