Component ​
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\Component
- Since
- 3.0.0
Component helper
Public Methods ​
Method | Description |
---|---|
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.
Arguments ​
$config
(array)
Returns ​
createComponent()
​
Instantiates and populates a component, and ensures that it is an instance of a given interface.
Arguments ​
$config
(string, array) – The component’s class name, or its config, with atype
value and optionally asettings
value.$instanceOf
(string, null) – The class or interface that the component must be an instance of.
Returns ​
\craft\helpers\T
– The component
Throws ​
- yii\base\InvalidConfigException
if $config doesn’t contain atype
value, or the type isn’t compatible with|null $instanceOf. - craft\errors\MissingComponentException
if the class specified by $config doesn’t exist, or belongs to an uninstalled plugin
iconSvg()
​
DEPRECATED
Deprecated in 5.0.0. craft\helpers\Cp::iconSvg() or craft\helpers\Cp::fallbackIconSvg() should be used instead.
- Since
- 3.5.0
Returns an SVG icon’s contents, namespaced and with aria-hidden="true"
added to it.
Arguments ​
$icon
(string, null) – The path to the SVG icon, or the actual SVG contents$label
(string) – The label of the component
Returns ​
mergeSettings()
​
Extracts settings from a given component config, and returns a new config array with the settings merged in.
Arguments ​
$config
(array)
Returns ​
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.
Arguments ​
$class
(string) – The component’s class name.$instanceOf
(string, 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 ​
Throws ​
- yii\base\InvalidConfigException
if $config doesn’t contain atype
value, or the type isn’t compatible with|null $instanceOf. - craft\errors\MissingComponentException
if the class specified by $config doesn’t exist, or belongs to an uninstalled plugin