Backend\Classes\WidgetBase

Extends:

Widget base class.

Public properties

public object $config

Supplied configuration.

public string $alias

Defined alias used 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

Specifies a path to the asset directory.

Show inherited public properties

Inherited public properties

Protected properties

protected Backend\Classes\Controller $controller

Backend controller object.

protected string $defaultAlias

A unique alias 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 $assets

Collection of assets to display in the layout.

protected array $assetBundles

Collection of combined and prioritized assets.

protected string $configPath

Specifies a path to the config directory.

protected array $emitterSingleEventCollection

Collection of registered events to be fired once only.

protected array $emitterEventCollection

Collection of registered events.

protected array $emitterEventSorted

Sorted collection of events.

protected string $fatalError

Object used for storing a fatal error.

Show inherited protected properties

Inherited protected properties

Public methods

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

Constructor

Parameters

public void addCss($name, $attributes=array())

addCss includes a StyleSheet asset to the asset list

Parameters
  • $name
  • $attributes

public void addCssBundle($name, $attributes=array())

addCssBundle includes a CSS asset to the bundled combiner stream

Parameters
  • $name
  • $attributes

public void addJs($name, $attributes=array())

addJs includes a JavaScript asset to the asset list

Parameters
  • $name
  • $attributes

public void addJsBundle($name, $attributes=array())

addJsBundle includes a JS asset to the bundled combiner stream

Parameters
  • $name
  • $attributes

public void addRss($name, $attributes=array())

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

Parameters
  • $name
  • $attributes

public void addViewPath(string|array $path)

addViewPath prepends a path on the available view path locations

Parameters
  • string|array $path

public self bindEvent($event, $callback, $priority=0)

Create a new event binding.

Parameters
  • $event
  • $callback
  • $priority

public self bindEventOnce($event, $callback)

Create a new event binding that fires once only

Parameters
  • $event
  • $callback

public void bindToController()

Binds a widget to the controller for safe use.

public void combineAssets($assets, $localPath='')

combineAssets runs asset paths through the Asset Combiner

Parameters
  • $assets
  • $localPath

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

Fire an event and call the listeners.

Parameters
  • string $event - Event name
  • array $params - Event parameters
  • boolean $halt - Halt after first non-null result

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

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);
Parameters
  • string $event - Event name
  • array $params - Event parameters
  • boolean $halt - Halt after first non-null result

public string fireViewEvent(string $event, array $params=array())

Special event function used for extending within view files, allowing HTML to be injected multiple times.

For example:

<?= $this->fireViewEvent('backend.auth.extendSigninView') ?>
Parameters
  • string $event - Event name
  • array $params - Event parameters

public void flushAssets()

Disables the use, and subequent 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 string getAssetPath(string $fileName, string $assetPath=NULL)

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.

Parameters
  • string $fileName - File to load.
  • string $assetPath - Explicitly define an asset path.

public array getAssetPaths()

Returns an array of all registered asset paths.

public string getConfig(string $name, string $default=NULL)

Safe accessor for configuration values.

Parameters
  • string $name - Config name, supports array names like "field[key]"
  • string $default - Default value if nothing is found

public string getConfigPath(string $fileName, mixed $configPath=NULL)

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.

Parameters
  • string $fileName - File to load.
  • mixed $configPath - Explicitly define a config path.

public void getController()

Returns the controller using this widget.

public string getEventHandler(string $name)

Returns a fully qualified event handler name for this widget.

Parameters
  • string $name - The ajax event handler name.

public void getFatalError()

getFatalError returns error message

public string getId(string $suffix=NULL)

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

Parameters
  • string $suffix - An extra string to append to the ID.

public string getViewPath(string $fileName, mixed $viewPath=NULL)

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.

Parameters
  • string $fileName - File to load.
  • mixed $viewPath - Explicitly define a view path.

public array getViewPaths()

getViewPaths returns the active view path locations

public string guessConfigPath(string $suffix='')

Guess the package path for the called class.

Parameters
  • string $suffix - An extra path to attach to the end

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

Guess the package path from a specified class.

Parameters
  • string $class - Class to guess path from.
  • string $suffix - An extra path to attach to the end

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

guessViewPath guesses the package path for the called class

Parameters
  • string $suffix - An extra path to attach to the end
  • bool $isPublic - Returns public path instead of an absolute one

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

guessViewPathFrom guesses the package path from a specified class

Parameters
  • string $class - Class to guess path from.
  • string $suffix - An extra path to attach to the end
  • bool $isPublic - Returns public path instead of an absolute one

public void handleError($exception)

Sets standard page variables in the case of a controller error.

Parameters
  • $exception

public void hasAssetsDefined()

hasAssetsDefined returns true if assets any have been added

public boolean hasFatalError()

public void init()

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

public string makeAssets(string $type=NULL)

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

Parameters
  • string $type - Return an asset collection of a given type (css, rss, js) or null for all.

public object makeConfig(array $configFile=array(), array $requiredConfig=array())

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

Parameters
  • array $configFile
  • array $requiredConfig

public stdClass makeConfigFromArray(array $configArray=array())

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

Parameters
  • array $configArray - Config array.

public string makeFileContents(string $filePath, array $extraParams=array())

makeFileContents includes a file path using output buffering

Parameters
  • string $filePath - Absolute path to the view file.
  • array $extraParams - Parameters that should be available to the view.

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

Makes a form widget object with the supplied form field and widget configuration.

Parameters
  • string $class - Widget class name
  • mixed $fieldConfig - A field name, an array of config or a FormField object.
  • array $widgetConfig - An array of config.

public mixed makeLayout(string $name=NULL, array $params=array(), bool $throwException=true)

makeLayout renders a layout

Parameters
  • string $name - Specifies the layout name. If this parameter is omitted, the $layout property will be used.
  • array $params - Parameter variables to pass to the view.
  • bool $throwException - Throw an exception if the layout is not found

public string makeLayoutPartial(string $partial, array $params=array())

makeLayoutPartial renders a layout partial

Parameters
  • string $partial - The view to load.
  • array $params - Parameter variables to pass to the view.

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

makePartial renders a partial file contents located in the views folder

Parameters
  • string $partial - The view to load.
  • array $params - Parameter variables to pass to the view.
  • bool $throwException - Throw an exception if the partial is not found.

public string makeView(string $view)

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"

Parameters
  • string $view - Specifies the view name, without extension. Eg: "index".

public string makeViewContent(string $contents, string $layout=NULL)

makeViewContent renders supplied contents inside a layout

Parameters
  • string $contents - The inner contents as a string.
  • string $layout - Specifies the layout name.

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

Makes a widget object with the supplied configuration file.

Parameters
  • string $class - Widget class name
  • array $widgetConfig - An array of config.

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

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

Parameters
  • mixed $configA
  • mixed $configB

public string render()

Renders the widget's primary contents.

public void resetSession()

Resets all session data related to this widget.

public self unbindEvent(string $event=NULL)

Destroys an event binding.

Parameters
  • string $event - Event to destroy

Show inherited public methods

Inherited public methods

Protected methods

protected void combineBundledAssets($type)

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

Parameters
  • $type

protected array emitterEventSortEvents(string $eventName)

Sort the listeners for a given event by priority.

Parameters
  • string $eventName

protected void fillFromConfig(array $properties=NULL)

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.

Parameters
  • array $properties

protected string getAssetEntryBuildPath(array $asset)

Internal helper, attaches a build code to an asset path

Parameters
  • array $asset - Stored asset array

protected string getAssetScheme(string $asset)

Internal helper, get asset scheme

Parameters
  • string $asset - Specifies a path (URL) to the asset.

protected void getLocalPath($relativePath)

getLocalPath converts a relative path to a local path

Parameters
  • $relativePath

protected string getSession(string $key=NULL, string $default=NULL)

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

Parameters
  • string $key - Unique key for the data store.
  • string $default - A default value to use when value is not found.

protected void handleViewException($e, $obLevel)

handleViewException handles a view exception

Parameters
  • $e
  • $obLevel

protected void loadAssets()

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

protected string makeSessionId()

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

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

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

Parameters
  • string $key - Unique key for the data store.
  • string $value - The value to store.

protected void removeDuplicates()

Removes duplicate assets from the entire collection.

protected void renderAssetAttributes($type, $asset)

renderAssetAttributes takes an asset definition and returns the necessary HTML output

Parameters
  • $type
  • $asset

Show inherited protected methods

Inherited protected methods

  • 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.