Cp ​
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\Cp
- Since
- 3.0.0
Class Cp
Public Methods ​
| Method | Description |
|---|---|
| addressFieldsHtml() | Returns address fields’ HTML (sans country) for a given address. |
| autosuggestFieldHtml() | Renders an autosuggest field’s HTML. |
| buttonGroupFieldHtml() | Renders a button group field’s HTML. |
| buttonGroupHtml() | Renders a button group. |
| buttonHtml() | Renders a button’s HTML. |
| cardPreviewHtml() | Returns HTML for the card preview based on selected fields and attributes. |
| cardViewDesignerHtml() | Renders a card view designer. |
| checkboxFieldHtml() | Renders a checkbox field’s HTML. |
| checkboxGroupFieldHtml() | Renders a checkbox group field’s HTML. |
| checkboxGroupHtml() | Renders a checkbox group input. |
| checkboxSelectFieldHtml() | Renders a checkbox select field’s HTML. |
| chipHtml() | Renders a component’s chip HTML. |
| colorFieldHtml() | Renders a color field’s HTML. |
| colorHtml() | Renders a color input’s HTML. |
| colorSelectFieldHtml() | Renders a color select field’s HTML. |
| componentPreviewHtml() | Returns component preview HTML, for a list of elements. |
| componentStatusIndicatorHtml() | Renders status indicator HTML for a craft\base\Statusable component. |
| componentStatusLabelHtml() | Renders status label HTML for a craft\base\Statusable component. |
| customSelectFieldHtml() | Renders a selectize field’s HTML. |
| customSelectHtml() | Renders a custom select input. |
| dateFieldHtml() | Returns a date field’s HTML. |
| dateHtml() | Returns a date input’s HTML. |
| dateTimeFieldHtml() | Renders a date + time field’s HTML. |
| disclosureMenu() | Returns a disclosure menu’s HTML. |
| earthIcon() | Returns the appropriate Earth icon, depending on the system time zone. |
| editableTableFieldHtml() | Renders an editable table field’s HTML. |
| editableTableHtml() | Renders an editable table’s HTML. |
| elementCardHtml() | Renders an element’s card HTML. |
| elementChipHtml() | Renders an element’s chip HTML. |
| elementHtml() | Renders an element’s chip HTML. |
| elementIndexHtml() | Returns the HTML for an element index. |
| elementPreviewHtml() | Returns element preview HTML, for a list of elements. |
| elementSelectFieldHtml() | Renders an element select field’s HTML. |
| elementSelectHtml() | Renders an element select input’s HTML |
| entryTypeSelectFieldHtml() | Renders an entry type select field’s HTML. |
| entryTypeSelectHtml() | Renders an entry type select input’s HTML |
| fallbackIconSvg() | Returns a fallback icon SVG for a component with a given label. |
| fieldHtml() | Renders a field’s HTML, for the given input HTML or a template. |
| fieldLayoutDesignerHtml() | Renders a field layout designer. |
| generatedFieldsTableHtml() | Renders a Generated Fields table for a field layout |
| iconPickerFieldHtml() | Renders an icon picker field’s HTML. |
| iconPickerHtml() | Renders an icon picker’s HTML. |
| iconSvg() | Returns an SVG icon’s contents for the control panel. |
| layoutElementSelectorHtml() | Renders a field layout element’s selector HTML. |
| lightswitchFieldHtml() | Renders a lightswitch field’s HTML. |
| lightswitchHtml() | Renders a lightswitch input’s HTML. |
| menuItem() | Returns a menu item’s HTML. |
| metadataHtml() | Returns a metadata component’s HTML. |
| moneyFieldHtml() | Renders a money field’s HTML. |
| moneyInputHtml() | Renders a money input’s HTML. |
| multiSelectFieldHtml() | Renders a multi-select field’s HTML. |
| multiSelectHtml() | Renders a multi-select input. |
| normalizeMenuItems() | Normalizes and cleans up the given disclosure menu items. |
| parseMarkdown() | Processes the given text as Markdown, with extra defenses against invalid tags and double-encoded entities. |
| rangeFieldHtml() | Renders a range field’s HTML. |
| rangeHtml() | Renders a range input’s HTML. |
| readOnlyNoticeHtml() | Returns the notice that should show when admin is viewing the available settings pages while allowAdminChanges is set to false. |
| renderTemplate() | Renders a control panel template. |
| requestedSite() | Returns the site the control panel is currently working with, via a site query string param if sent. |
| reset() | Resets requestedSite(). |
| selectFieldHtml() | Renders a select field’s HTML. |
| selectHtml() | Renders a select input. |
| selectizeFieldHtml() | Renders a selectize field’s HTML. |
| selectizeHtml() | Renders a selectize input. |
| siteMenuItems() | Returns a menu item array for the given sites, possibly grouping them by site group. |
| statusIndicatorHtml() | Renders status indicator HTML. |
| statusLabelHtml() | Renders status label HTML. |
| textFieldHtml() | Renders a text field’s HTML. |
| textHtml() | Renders a text input’s HTML. |
| textareaFieldHtml() | Renders a textarea field’s HTML. |
| textareaHtml() | Renders a textarea input’s HTML. |
| timeFieldHtml() | Returns a date field’s HTML. |
| timeHtml() | Returns a time input’s HTML. |
addressFieldsHtml() ​
- Since
- 4.0.0
Returns address fields’ HTML (sans country) for a given address.
Arguments ​
$address(craft\elements\Address)$static(boolean)
Returns ​
autosuggestFieldHtml() ​
- Since
- 3.7.0
Renders an autosuggest field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
buttonGroupFieldHtml() ​
- Since
- 5.8.0
Renders a button group field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
buttonGroupHtml() ​
- Since
- 5.8.0
Renders a button group.
Arguments ​
$config(array)
Returns ​
buttonHtml() ​
- Since
- 5.7.0
Renders a button’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
cardPreviewHtml() ​
Returns HTML for the card preview based on selected fields and attributes.
Arguments ​
$fieldLayout(craft\models\FieldLayout)$cardElements(array)$showThumb
Returns ​
Throws ​
cardViewDesignerHtml() ​
- Since
- 5.5.0
Renders a card view designer.
Arguments ​
$fieldLayout(craft\models\FieldLayout)$config(array)
Returns ​
checkboxFieldHtml() ​
- Since
- 3.6.0
Renders a checkbox field’s HTML.
Note that unlike the checkboxField macro in _includes/forms.html, you must set the checkbox label via $config['checkboxLabel'].
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
checkboxGroupFieldHtml() ​
- Since
- 5.0.0
Renders a checkbox group field’s HTML.
Arguments ​
$config(array)
Returns ​
checkboxGroupHtml() ​
- Since
- 5.0.0
Renders a checkbox group input.
Arguments ​
$config(array)
Returns ​
checkboxSelectFieldHtml() ​
- Since
- 3.6.0
Renders a checkbox select field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
chipHtml() ​
- Since
- 5.0.0
Renders a component’s chip HTML.
The following config settings can be passed to $config:
attributes– Any custom HTML attributes that should be set on the chipautoReload– Whether the chip should auto-reload itself when it’s savedid– The chip’sidattributeinputName– Thenameattribute that should be set on a hidden input, if setinputValue– Thevalueattribute that should be set on the hidden input, ifinputNameis set. Defaults to [[\craft\base\Identifiable::getId()`]].labelHtml– The label HTML, if it should be different from craft\base\Chippable::getUiLabel()selectable– Whether the chip should include a checkbox inputshowActionMenu– Whether the chip should include an action menushowLabel– Whether the component’s label should be shownshowHandle– Whether the component’s handle should be show (only applies if the component implements craft\base\Grippable)showStatus– Whether the component’s status should be shown (if it has statuses)showThumb– Whether the component’s thumbnail should be shown (if it has one)size– The size of the chip (smallorlarge)sortable– Whether the chip should include a drag handle
Arguments ​
$component(craft\base\Chippable) – The component that the chip represents$config(array) – Chip configuration
Returns ​
colorFieldHtml() ​
- Since
- 3.6.0
Renders a color field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
colorHtml() ​
- Since
- 5.6.0
Renders a color input’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
colorSelectFieldHtml() ​
- Since
- 5.0.0
Renders a color select field’s HTML.
Arguments ​
$config(array)
Returns ​
componentPreviewHtml() ​
- Since
- 5.4.0
Returns component preview HTML, for a list of elements.
Arguments ​
$components(craft\base\Chippable[]) – The components$chipConfig(array)
Returns ​
componentStatusIndicatorHtml() ​
- Since
- 5.2.0
Renders status indicator HTML for a craft\base\Statusable component.
Arguments ​
$component(craft\base\Statusable)
Returns ​
componentStatusLabelHtml() ​
- Since
- 5.2.0
Renders status label HTML for a craft\base\Statusable component.
Arguments ​
$component(craft\base\Statusable)
Returns ​
customSelectFieldHtml() ​
- Since
- 5.0.0
Renders a selectize field’s HTML.
Arguments ​
$config(array)
Returns ​
customSelectHtml() ​
- Since
- 5.0.0
Renders a custom select input.
Arguments ​
$config(array)
Returns ​
dateFieldHtml() ​
- Since
- 4.0.0
Returns a date field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
dateHtml() ​
- Since
- 4.0.0
Returns a date input’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
dateTimeFieldHtml() ​
- Since
- 3.7.0
Renders a date + time field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
disclosureMenu() ​
- Since
- 5.0.0
Returns a disclosure menu’s HTML.
See menuItem() for a list of supported item config options.
Horizontal rules can be defined with the following key:
hr– Set totrue
Groups of items can be defined as well, using the following keys:
group– Set totrueheading– The group headingitems– The nested item definitionslistAttributes– any HTML attributes that should be included on the<ul>
Arguments ​
Returns ​
earthIcon() ​
- Since
- 5.0.0
Returns the appropriate Earth icon, depending on the system time zone.
Returns ​
editableTableFieldHtml() ​
- Since
- 3.6.0
Renders an editable table field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
editableTableHtml() ​
- Since
- 5.8.0
Renders an editable table’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
elementCardHtml() ​
- Since
- 5.0.0
Renders an element’s card HTML.
The following config settings can be passed to $config:
attributes– Any custom HTML attributes that should be set on the cardautoReload– Whether the card should auto-reload itself when it’s savedcontext– The context the chip is going to be shown in (index,field, etc.)id– The card’sidattributeinputName– Thenameattribute that should be set on the hidden input, ifcontextis set tofieldselectable– Whether the card should include a checkbox inputshowActionMenu– Whether the card should include an action menusortable– Whether the card should include a drag handle
Arguments ​
$element(craft\base\ElementInterface) – The element to be rendered$config(array) – Card configuration
Returns ​
elementChipHtml() ​
- Since
- 5.0.0
Renders an element’s chip HTML.
The following config settings can be passed to $config:
attributes– Any custom HTML attributes that should be set on the chipautoReload– Whether the chip should auto-reload itself when it’s savedcontext– The context the chip is going to be shown in (index,field, etc.)id– The chip’sidattributeinputName– Thenameattribute that should be set on the hidden input, ifcontextis set tofieldselectable– Whether the chip should include a checkbox inputshowActionMenu– Whether the chip should include an action menushowDraftName– Whether to show the draft name beside the label if the element is a draft of a published elementshowLabel– Whether the element’s label should be shownshowStatus– Whether the element’s status should be shown (if the element type has statuses)showThumb– Whether the element’s thumbnail should be shown (if the element has one)size– The size of the chip (smallorlarge)sortable– Whether the chip should include a drag handle
Arguments ​
$element(craft\base\ElementInterface) – The element to be rendered$config(array) – Chip configuration
Returns ​
elementHtml() ​
DEPRECATED
Deprecated in 5.0.0. elementChipHtml() or elementCardHtml() should be used instead.
- Since
- 3.5.8
Renders an element’s chip HTML.
Arguments ​
$element(craft\base\ElementInterface) – The element to be rendered$context(string) – The context the chip is going to be shown in (index,field, etc.)$size(string) – The size of the chip (smallorlarge)$inputName(string, null) – Thenameattribute that should be set on the hidden input, if$contextis set tofield$showStatus(boolean) – Whether the element status should be shown (if the element type has statuses)$showThumb(boolean) – Whether the element thumb should be shown (if the element has one)$showLabel(boolean) – Whether the element label should be shown$showDraftName(boolean) – Whether to show the draft name beside the label if the element is a draft of a published element$single(boolean) – Whether the input name should omit the trailing[]$autoReload(boolean) – Whether the element should auto-reload itself when it’s saved
Returns ​
elementIndexHtml() ​
- Since
- 5.0.0
Returns the HTML for an element index.
Arguments ​
$elementType(class-string<\craft\base\ElementInterface>)$config(array)
Returns ​
elementPreviewHtml() ​
- Since
- 3.6.3
Returns element preview HTML, for a list of elements.
Arguments ​
$elements(craft\base\ElementInterface[]) – The elements$size(string) – The size of the element (smallorlarge)$showStatus(boolean) – Whether the element status should be shown (if the element type has statuses)$showThumb(boolean) – Whether the element thumb should be shown (if the element has one)$showLabel(boolean) – Whether the element label should be shown$showDraftName(boolean) – Whether to show the draft name beside the label if the element is a draft of a published element
Returns ​
elementSelectFieldHtml() ​
- Since
- 3.7.0
Renders an element select field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
elementSelectHtml() ​
- Since
- 4.0.0
Renders an element select input’s HTML
Arguments ​
$config(array)
Returns ​
Throws ​
entryTypeSelectFieldHtml() ​
- Since
- 5.0.0
Renders an entry type select field’s HTML.
Arguments ​
$config(array)
Returns ​
entryTypeSelectHtml() ​
- Since
- 5.0.0
Renders an entry type select input’s HTML
Arguments ​
$config(array)
Returns ​
fallbackIconSvg() ​
- Since
- 5.0.0
Returns a fallback icon SVG for a component with a given label.
Arguments ​
$label(string)
Returns ​
fieldHtml() ​
- Since
- 3.5.8
Renders a field’s HTML, for the given input HTML or a template.
Arguments ​
$input(string, callable) – The input HTML or template path. If passing a template path, it must begin withtemplate:.$config(array)
Returns ​
Throws ​
- craft\web\twig\TemplateLoaderException
if $input begins withtemplate:and is followed by an invalid template path - yii\base\InvalidArgumentException
if$config['siteId']is invalid
fieldLayoutDesignerHtml() ​
- Since
- 4.0.0
Renders a field layout designer.
Arguments ​
$fieldLayout(craft\models\FieldLayout)$config(array)
Returns ​
generatedFieldsTableHtml() ​
Renders a Generated Fields table for a field layout
Arguments ​
$fieldLayout(craft\models\FieldLayout)$config(array)
Returns ​
iconPickerFieldHtml() ​
- Since
- 5.0.0
Renders an icon picker field’s HTML.
Arguments ​
$config(array)
Returns ​
iconPickerHtml() ​
- Since
- 5.0.0
Renders an icon picker’s HTML.
Arguments ​
$config(array)
Returns ​
iconSvg() ​
- Since
- 5.0.0
Returns an SVG icon’s contents for the control panel.
The icon can be a system icon’s name (e.g. 'whiskey-glass-ice'), the path to an SVG file, or raw SVG markup.
System icons can be found in src/icons/solid/.
Arguments ​
Returns ​
layoutElementSelectorHtml() ​
- Since
- 5.0.0
Renders a field layout element’s selector HTML.
Arguments ​
$element(craft\base\FieldLayoutElement)$forLibrary(boolean)$attributes(array)
Returns ​
lightswitchFieldHtml() ​
- Since
- 3.6.0
Renders a lightswitch field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
lightswitchHtml() ​
- Since
- 4.0.0
Renders a lightswitch input’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
menuItem() ​
- Since
- 5.0.0
Returns a menu item’s HTML.
The item config can contain a type key set to a \craft\enums\MenuItemType case. By default, it will be set to:
MenuItemType::Linkifurlis setMenuItemType::Groupifheadingoritemsare setMenuItemType::Buttonin all other cases
Link and button item configs can contain the following keys:
id– The item’s IDlabel– The item label, to be HTML-encodedicon– The item icon namehtml– The item label, which will be output verbatim, without being HTML-encodeddescription– The item descriptionstatus– The status indicator that should be shown beside the item labelurl– The URL that the item should link toaction– The controller action that the item should triggerparams– Request parameters that should be sent to theactionconfirm– A confirmation message that should be presented to the user before triggering theactionredirect– The redirect path that theactionshould userequireElevatedSession– Whether an elevated session is required before theactionis triggeredselected– Whether the item should be marked as selectedhidden– Whether the item should be hiddenattributes– Any HTML attributes that should be set on the item’s<a>or<button>tagliAttributes– Any HTML attributes that should be set on the item’s<li>tag
Arguments ​
Returns ​
metadataHtml() ​
Returns a metadata component’s HTML.
Arguments ​
$data(array) – The data, with keys representing the labels. The values can either be strings or callables. If a value isfalse, it will be omitted.
Returns ​
moneyFieldHtml() ​
- Since
- 5.0.0
Renders a money field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
moneyInputHtml() ​
- Since
- 5.0.0
Renders a money input’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
multiSelectFieldHtml() ​
- Since
- 4.0.0
Renders a multi-select field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
multiSelectHtml() ​
- Since
- 4.0.0
Renders a multi-select input.
Arguments ​
$config(array)
Returns ​
normalizeMenuItems() ​
- Since
- 5.0.0
Normalizes and cleans up the given disclosure menu items.
Arguments ​
$items(array)
Returns ​
parseMarkdown() ​
- Since
- 5.8.3
Processes the given text as Markdown, with extra defenses against invalid tags and double-encoded entities.
Arguments ​
Returns ​
rangeFieldHtml() ​
- Since
- 5.5.0
Renders a range field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
rangeHtml() ​
- Since
- 5.5.0
Renders a range input’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
readOnlyNoticeHtml() ​
- Since
- 5.6.0
Returns the notice that should show when admin is viewing the available settings pages while allowAdminChanges is set to false.
Returns ​
renderTemplate() ​
Renders a control panel template.
Arguments ​
Returns ​
Throws ​
- craft\web\twig\TemplateLoaderException
if$templateis an invalid template path
requestedSite() ​
- Since
- 4.0.0
Returns the site the control panel is currently working with, via a site query string param if sent.
Returns ​
craft\models\Site, null – The site, or null if the user doesn’t have permission to edit any sites.
reset() ​
- Since
- 5.7.0
Resets requestedSite().
selectFieldHtml() ​
- Since
- 3.6.0
Renders a select field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
selectHtml() ​
- Since
- 3.6.0
Renders a select input.
Arguments ​
$config(array)
Returns ​
selectizeFieldHtml() ​
- Since
- 4.0.0
Renders a selectize field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
selectizeHtml() ​
- Since
- 4.0.0
Renders a selectize input.
Arguments ​
$config(array)
Returns ​
siteMenuItems() ​
- Since
- 5.0.0
Returns a menu item array for the given sites, possibly grouping them by site group.
Arguments ​
$sites(array<int,\craft\models\Site|array{site: \craft\models\Site, status?: string}>)$selectedSite(craft\models\Site, null)$config(array)
Returns ​
statusIndicatorHtml() ​
- Since
- 5.0.0
Renders status indicator HTML.
When the status is equal to "draft" the draft icon will be displayed. The attributes passed as the second argument should be a status definition from craft\base\ElementInterface::statuses()
Arguments ​
Returns ​
statusLabelHtml() ​
- Since
- 5.2.0
Renders status label HTML.
When the status is equal to "draft" the draft icon will be displayed. The attributes passed as the second argument should be a status definition from craft\base\ElementInterface::statuses()
Arguments ​
$config(array) – Config options
Returns ​
textFieldHtml() ​
- Since
- 3.6.0
Renders a text field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
textHtml() ​
- Since
- 4.0.0
Renders a text input’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
textareaFieldHtml() ​
- Since
- 3.6.0
Renders a textarea field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
textareaHtml() ​
- Since
- 4.0.0
Renders a textarea input’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
timeFieldHtml() ​
- Since
- 4.0.0
Returns a date field’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if$config['siteId']is invalid
timeHtml() ​
- Since
- 4.0.0
Returns a time input’s HTML.
Arguments ​
$config(array)
Returns ​
Throws ​
Constants ​
| Constant | Description |
|---|---|
CHIP_SIZE_LARGE | |
CHIP_SIZE_SMALL | |
ELEMENT_SIZE_LARGE | |
ELEMENT_SIZE_SMALL |
Events ​
EVENT_DEFINE_ELEMENT_CARD_HTML ​
- Type
- craft\events\DefineElementHtmlEvent
- Since
- 5.0.0
The event that is triggered when defining an element’s card HTML.
See also elementCardHtml()
EVENT_DEFINE_ELEMENT_CHIP_HTML ​
- Type
- craft\events\DefineElementHtmlEvent
- Since
- 5.0.0
The event that is triggered when defining an element’s chip HTML.
See also elementChipHtml()
EVENT_DEFINE_ELEMENT_INNER_HTML ​
DEPRECATED
Deprecated in 5.0.0. EVENT_DEFINE_ELEMENT_CHIP_HTML should be used instead.
- Type
- craft\events\DefineElementInnerHtmlEvent
- Since
- 4.0.0
The event that is triggered when defining an element’s inner HTML.
EVENT_REGISTER_ALERTS ​
The event that is triggered when registering control panel alerts.