Cms\Classes\ComponentBase

Overview

ComponentBase class

Extends
Implements
  • October\Contracts\Twig\CallsAnyMethod
  • Stringable

Public Properties

public string $id

id is a unique identifier for this component.

public string $alias

alias used for this component.

public string $name

name as a class name or class alias used in the component declaration in a template.

public boolean $isHidden

isHidden determines whether the component is hidden from the backend UI.

public string $pluginIcon

pluginIcon of the plugin that defines the component. This field is used by the CMS internally.

public string $componentCssClass

componentCssClass name for the backend page/layout component list. This field is used by the CMS internally.

public boolean $inspectorEnabled

inspectorEnabled determines whether Inspector can be used with the component. This field is used by the CMS internally.

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 string $dirName

dirName specifies the component directory name.

protected Cms\Classes\Controller $controller

controller object.

protected Cms\Classes\PageCode $page

page object object.

protected array $externalPropertyNames

externalPropertyNames is a collection of external property names used by this component.

protected string $componentGetPathCache

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 array $emitterSingleEventCollection

emitterSingleEventCollection of events to be fired once only

protected array $emitterEventCollection

emitterEventCollection of all registered events

protected array $emitterEventSorted

emitterEventSorted collection

protected DependencyResolver $dependencyResolver

dependencyResolver for AJAX handlers and controller actions.

protected array $properties

properties contains the object property values.

Show inherited protected properties

Inherited Protected Properties


Public Methods

public __call()

public __call(string $method, array $parameters): mixed 

__call dynamically handles calls into the controller instance.

public __construct()

public __construct(
    CodeBase|null $cmsObject = null,
    array $properties = []
): void

__construct the component, which takes in the page or layout code section object and properties set by the page or layout.

public __toString()

public __toString(): string 

toString returns the component's alias, used by SELF__

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

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

combineAssets runs asset paths through the Asset Combiner

public componentDetails()

public componentDetails(): void

componentDetails returns information about this component, including name and description

public defineProperties()

public defineProperties(): void

defineProperties used by this class. This method should be used as an override in the extended class.

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

public getController(): void

getController returns the controller using this component.

public getPath()

public getPath(): void

getPath returns the absolute component path

public getProperties()

public getProperties(): array 

getProperties returns all properties.

public getPropertyOptions()

public getPropertyOptions(string $property): array 

getPropertyOptions returns options for multi-option properties (drop-downs, etc.)

public hasAssetsDefined()

public hasAssetsDefined(): bool 

hasAssetsDefined returns true if assets any have been added

public init()

public init(): void

init is executed when this component is first initialized, before AJAX requests.

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

public makePrimaryAccessor(): void

makePrimaryAccessor returns the PHP object variable for the Twig view layer.

public onRender()

public onRender(): void

onRender is executed when this component is rendered on a page or layout.

public onRun()

public onRun(): void

onRun is executed when this component is bound to a page or layout, part of the page life cycle.

public paramName()

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

paramName returns the external property name when the property value is a routing parameter reference. Otherwise the default value specified is returned.

public property()

public property(string $name, ?string $default = null): ?string 

property returns a defined property value or default if one is not set.

public propertyName()

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

propertyName returns the external property name when the property value is an external property reference. Otherwise the default value specified is returned.

public renderPartial()

public renderPartial(): void

renderPartial renders a requested partial in context of this component, see Cms\Classes\Controller@renderPartial for usage.

public runAjaxHandler()

public runAjaxHandler($handler): boolean 

runAjaxHandler executes the event cycle when running an AJAX handler.

public runLifeCycle()

public runLifeCycle(): void

runLifeCycle executes the life cycle for the component.

public setExternalPropertyName()

public setExternalPropertyName(string $name, string $extName): void 

setExternalPropertyName sets an external property name.

public setExternalPropertyNames()

public setExternalPropertyNames(array $names): void 

setExternalPropertyNames sets names used by external properties.

public setProperties()

public setProperties(array $properties): void 

setProperties for multiple values

public setProperty()

public setProperty(string $name, mixed $value): void 

setProperty for a single value

public unbindEvent()

public unbindEvent($event = null): void 

unbindEvent destroys an event binding

public validateProperties()

public validateProperties(array $properties): array 

validateProperties against the defined properties of the class. This method also sets default properties.

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

protected getComponentAssetRelativePath(): string 

protected getComponentAssetUrlPath()

protected getComponentAssetUrlPath(): string 

getComponentAssetUrlPath returns the public directory for the component assets

protected getLocalPath()

protected getLocalPath($relativePath): string 

getLocalPath converts a relative path to a local path

protected makeCallMethod()

protected makeCallMethod($instance, $method, $parameters = []): void

makeCallMethod will prepare method args with DI and call the method

protected processAssetAttributes()

protected processAssetAttributes($attributes): void

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