Backend\Classes\WidgetBase

Overview

WidgetBase class

Extends

Public Properties

public object $config

config supplied.

public string $alias

alias defined for this widget.

public array $vars

vars is a list of variables to pass to the page

public string $layout

layout to use for the view

public bool $suppressLayout

suppressLayout prevents the use of a layout

public string $assetPath

assetPath specifies the relative path to the asset directory.

public string $assetUrlPath

assetUrlPath specifies the public path to the asset directory.

Show inherited public properties

Inherited Public Properties

Protected Properties

protected Backend\Classes\Controller $controller

controller for the backend.

protected string $defaultAlias

defaultAlias to identify this widget.

protected string|array $viewPath

viewPath specifies a path to the views directory

protected string $layoutPath

layoutPath specifies a path to the layout directory

protected array $viewPathGuessCache

viewPathGuessCache remembers path guesses for performance.

protected array $assets

Collection of assets to display in the layout.

protected array $assetBundles

Collection of combined and prioritized assets.

protected string $assetDefaults

assetDefaults is the default attributes for assets.

protected string $configPath

configPath specifies a path to the config directory.

protected array $emitterSingleEventCollection

emitterSingleEventCollection of events to be fired once only

protected array $emitterEventCollection

emitterEventCollection of all registered events

protected array $emitterEventSorted

emitterEventSorted collection

protected string|null $fatalError

fatalError stores the object used for a fatal error.

Show inherited protected properties

Inherited Protected Properties


Public Methods

public __construct()

public __construct(
    Backend\Classes\Controller $controller,
    array $configuration = []
): void

__construct the widget

public addCss()

public addCss($name, $attributes = []): void

addCss includes a StyleSheet asset to the asset list

public addCssBundle()

public addCssBundle($name, $attributes = []): void

addCssBundle includes a CSS asset to the bundled combiner pipeline

public addJs()

public addJs($name, $attributes = []): void

addJs includes a JavaScript asset to the asset list

public addJsBundle()

public addJsBundle($name, $attributes = []): void

addJsBundle includes a JS asset to the bundled combiner pipeline

public addRss()

public addRss($name, $attributes = []): void

addRss adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

public addViewPath()

public addViewPath(string|array $path, $append = false): void 

addViewPath prepends a path on the available view path locations

public bindEvent()

public bindEvent($event, $callback, $priority = 0): void 

bindEvent creates a new event binding

public bindEventOnce()

public bindEventOnce($event, $callback, $priority = 0): void 

bindEventOnce creates a new event binding that fires once only

public bindToController()

public bindToController(): void 

bindToController binds a widget to the controller for safe use.

public combineAssets()

public combineAssets($assets, $localPath = ''): string 

combineAssets runs asset paths through the Asset Combiner

public fireEvent()

public fireEvent(
    string $event,
    array $params = [],
    boolean $halt = false
): array 

fireEvent and call the listeners

public fireSystemEvent()

public fireSystemEvent(
    string $event,
    array $params = [],
    boolean $halt = true
): mixed 

fireSystemEvent fires a combination of local and global events. The first segment is removed from the event name locally and the local object is passed as the first argument to the event globally. Halting is also enabled by default.

For example:

$this->fireSystemEvent('backend.list.myEvent', ['my value']);

Is equivalent to:

$this->fireEvent('list.myEvent', ['myvalue'], true);

Event::fire('backend.list.myEvent', [$this, 'myvalue'], true);

public fireViewEvent()

public fireViewEvent(string $event, array $params = []): string 

fireViewEvent is a special event function used for extending within view files, allowing HTML to be injected multiple times.

For example:

<?= $this->fireViewEvent('backend.auth.extendSigninView') ?>

public flushAssets()

public flushAssets(): void 

flushAssets disables the use, and subsequent broadcast, of assets. This is useful to call during an AJAX request to speed things up. This method works by specifically targeting the hasAssetsDefined method.

public getAssetPath()

public getAssetPath(
    string $fileName,
    string $assetPath = null
): string 

getAssetPath locates a file based on it's definition. If the file starts with a forward slash, it will be returned in context of the application public path, otherwise it will be returned in context of the asset path.

public getAssetPaths()

public getAssetPaths(): array 

getAssetPaths returns an array of all registered asset paths.

public getConfig()

public getConfig(string $name = null, mixed $default = null): string 

getConfig is a safe accessor for configuration values

public getConfigPath()

public getConfigPath(
    string $fileName,
    mixed $configPath = null
): string 

getConfigPath locates a file based on it's definition. If the file starts with the ~ symbol it will be returned in context of the application base path, otherwise it will be returned in context of the config path.

public getController()

public getController(): void

getController returns the controller using this widget.

public getEventHandler()

public getEventHandler(string $name): string 

getEventHandler returns a fully qualified event handler name for this widget.

public getFatalError()

public getFatalError(): void

getFatalError returns error message

public getId()

public getId(string $suffix = null): string 

getId returns a unique ID for this widget. Useful in creating HTML markup.

public getViewPath()

public getViewPath(string $fileName, mixed $viewPath = null): string 

getViewPath locates a file based on its definition. The file name can be prefixed with a symbol (~|$) to return in context of the application or plugin base path, otherwise it will be returned in context of this object view path.

public getViewPaths()

public getViewPaths(): array 

getViewPaths returns the active view path locations

public getWidget()

public getWidget($name): void

public guessConfigPath()

public guessConfigPath(string $suffix = ''): string 

guessConfigPath guesses the package path for the called class.

public guessConfigPathFrom()

public guessConfigPathFrom(string $class, string $suffix = ''): string 

guessConfigPathFrom guesses the package path from a specified class.

public guessViewPath()

public guessViewPath(
    string $suffix = '',
    bool $isPublic = false
): string 

guessViewPath guesses the package path for the called class

public guessViewPathFrom()

public guessViewPathFrom(
    string $class,
    string $suffix = '',
    bool $isPublic = false
): string 

guessViewPathFrom guesses the package path from a specified class, including an optional suffix to attach at the end, and the option to return a public path instead of a local one.

public handleError()

public handleError($exception): void

handleError sets standard page variables in the case of a controller error.

public hasAssetsDefined()

public hasAssetsDefined(): bool 

hasAssetsDefined returns true if assets any have been added

public hasFatalError()

public hasFatalError(): void

hasFatalError returns true if a fatal error has been set.

public init()

public init(): void 

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

public makeAssets()

public makeAssets(string $type = null): string 

makeAssets outputs <link> and <script> tags to load assets previously added with addJs and addCss method calls

public makeConfig()

public makeConfig(
    mixed $configFile = [],
    array $requiredConfig = []
): object 

makeConfig reads the contents of the supplied file and applies it to this object.

public makeConfigFromArray()

public makeConfigFromArray(array $configArray = []): stdClass 

makeConfigFromArray makes a config object from an array, making the first level keys properties of a new object.

public makeFileContents()

public makeFileContents(
    string $filePath,
    array $extraParams = []
): string 

makeFileContents includes a file path using output buffering

public makeFormWidget()

public makeFormWidget(
    string $class,
    mixed $fieldConfig = [],
    array $widgetConfig = []
): Backend\Classes\FormWidgetBase 

makeFormWidget object with the supplied form field and widget configuration.

public makeLayout()

public makeLayout(
    string $name = null,
    array $params = [],
    bool $throwException = true
): mixed 

makeLayout renders a layout

public makeLayoutPartial()

public makeLayoutPartial(string $partial, array $params = []): string 

makeLayoutPartial renders a layout partial

public makePartial()

public makePartial(
    string $partial,
    array $params = [],
    bool $throwException = true
): mixed 

makePartial renders a partial file contents located in the views folder

public makeView()

public makeView(string $view): string 

makeView loads a view with the name specified. Applies layout if its name is provided by the parent object. The view file must be situated in the views directory, and has the extension "htm" or "php"

public makeViewContent()

public makeViewContent(
    string $contents,
    string $layout = null
): string 

makeViewContent renders supplied contents inside a layout

public makeWidget()

public makeWidget(
    string $class,
    array $widgetConfig = []
): Backend\Classes\WidgetBase 

makeWidget object with the supplied configuration file.

public mergeConfig()

public mergeConfig(mixed $configA, mixed $configB): stdClass 

mergeConfig merges two configuration sources, either prepared or not, and returns them as a single configuration object.

public render()

public render(): string 

render the widget's primary contents.

public resetSession()

public resetSession(): void 

Resets all session data related to this widget.

public unbindEvent()

public unbindEvent($event = null): void 

unbindEvent destroys an event binding

Show inherited public methods

Inherited Public Methods

Protected Methods

protected combineBundledAssets()

protected combineBundledAssets($type): array 

combineBundledAssets spins over every bundle definition and combines them to an asset

protected emitterEventSortEvents()

protected emitterEventSortEvents($eventName, $combined = []): array 

emitterEventSortEvents sorts the listeners for a given event by priority

protected fillFromConfig()

protected fillFromConfig(array $properties = null): void 

fillFromConfig transfers config values stored inside the $config property directly on to the root object properties. If no properties are defined all config will be transferred if it finds a matching property.

protected getAssetEntryBuildPath()

protected getAssetEntryBuildPath(array $asset): string 

Internal helper, attaches a build code to an asset path

protected getAssetScheme()

protected getAssetScheme($asset): string 

getAssetScheme is an internal helper to get the asset scheme.

protected getConfigValueFrom()

protected getConfigValueFrom($configObj, $name = null, $default = null): void

getConfigValueFrom will apply the config getter convention

protected getLocalPath()

protected getLocalPath($relativePath): string 

getLocalPath converts a relative path to a local path

protected getSession()

protected getSession(
    string $key = null,
    string $default = null
): string 

Retrieves a widget related key/value pair from session data.

protected handleViewException()

protected handleViewException($e, $obLevel): void 

handleViewException handles a view exception

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

protected makeSessionId(): string 

Returns a unique session identifier for this widget and controller action.

protected processAssetAttributes()

protected processAssetAttributes($attributes): void

protected putSession()

protected putSession(string $key, string $value): void 

Saves a widget related key/value pair in to session data.

protected removeDuplicateAssets()

protected removeDuplicateAssets(): void

removeDuplicateAssets removes duplicate and global assets from the entire collection

protected renderAssetAttributes()

protected renderAssetAttributes($type, $asset): string 

renderAssetAttributes takes an asset definition and returns the necessary HTML output

Show inherited protected methods

Inherited Protected Methods