Skip to content

Component ​

Type
Class
Namespace
craft\helpers
Inherits
craft\helpers\Component
Since
3.0.0

Component helper

View source

Public Methods ​

MethodDescription
cleanseConfig()Cleanses a component config of any on X or as X keys.
createComponent()Instantiates and populates a component, and ensures that it is an instance of a given interface.
iconSvg()Returns an SVG icon’s contents, namespaced and with aria-hidden="true" added to it.
mergeSettings()Extracts settings from a given component config, and returns a new config array with the settings merged in.
validateComponentClass()Returns whether a component class exists, is an instance of a given interface, and doesn't belong to a disabled plugin.

cleanseConfig() ​

Since
4.4.15

Cleanses a component config of any on X or as X keys.

View source

Arguments ​

Returns ​

array

createComponent() ​

Instantiates and populates a component, and ensures that it is an instance of a given interface.

View source

Arguments ​

  • $config (class-string<\craft\helpers\T>, array) – The component’s class name, or its config, with a type value and optionally a settings value.
  • $instanceOf (class-string<\craft\helpers\T>, null) – The class or interface that the component must be an instance of.

Returns ​

\craft\helpers\T – The component

Throws ​

iconSvg() ​

Since
3.5.0

Returns an SVG icon’s contents, namespaced and with aria-hidden="true" added to it.

View source

Arguments ​

  • $icon (string, null) – The path to the SVG icon, or the actual SVG contents
  • $label (string) – The label of the component

Returns ​

string

mergeSettings() ​

Extracts settings from a given component config, and returns a new config array with the settings merged in.

View source

Arguments ​

Returns ​

array

validateComponentClass() ​

Since
3.2.0

Returns whether a component class exists, is an instance of a given interface, and doesn't belong to a disabled plugin.

View source

Arguments ​

  • $class (class-string<\craft\base\ComponentInterface>) – The component’s class name.
  • $instanceOf (class-string<\craft\base\ComponentInterface>, null) – The class or interface that the component must be an instance of.
  • $throwException (boolean) – Whether an exception should be thrown if an issue is encountered

Returns ​

boolean

Throws ​