Cp
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\Cp
- Since
- 3.0.0
Class Cp
View source (opens new window)
# Public Methods
Method | Description |
---|---|
addressCardHtml() | Renders an address card for an Addresses input. |
addressCardsHtml() | Renders address cards. |
addressFieldsHtml() | Returns address fields’ HTML (sans country) for a given address. |
alerts() | |
autosuggestFieldHtml() | Renders an autosuggest field’s HTML. |
checkboxFieldHtml() | Renders a checkbox field’s HTML. |
checkboxSelectFieldHtml() | Renders a checkbox select field’s HTML. |
colorFieldHtml() | Renders a color field’s HTML. |
dateFieldHtml() | Returns a date field’s HTML. |
dateHtml() | Returns a date input’s HTML. |
dateTimeFieldHtml() | Renders a date + time field’s HTML. |
editableTableFieldHtml() | Renders an editable table field’s HTML. |
elementHtml() | Renders an element’s HTML. |
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 |
fieldHtml() | Renders a field’s HTML, for the given input HTML or a template. |
fieldLayoutDesignerHtml() | Renders a field layout designer. |
lightswitchFieldHtml() | Renders a lightswitch field’s HTML. |
lightswitchHtml() | Renders a lightswitch input’s HTML. |
metadataHtml() | Returns a metadata component’s HTML. |
multiSelectFieldHtml() | Renders a multi-select field’s HTML. |
multiSelectHtml() | Renders a multi-select input. |
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. |
selectFieldHtml() | Renders a select field’s HTML. |
selectHtml() | Renders a select input. |
selectizeFieldHtml() | Renders a selectize field’s HTML. |
selectizeHtml() | Renders a selectize input. |
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. |
# addressCardHtml()
- Since
- 4.0.0
Renders an address card for an Addresses input.
View source (opens new window)
Arguments
$address
(craft\elements\Address)$config
(array (opens new window))
Returns
# addressCardsHtml()
- Since
- 4.0.0
Renders address cards.
View source (opens new window)
Arguments
$addresses
(craft\elements\Address[])$config
(array (opens new window))
Returns
# addressFieldsHtml()
- Since
- 4.0.0
Returns address fields’ HTML (sans country) for a given address.
View source (opens new window)
Arguments
$address
(craft\elements\Address)
Returns
# alerts()
View source (opens new window)
Arguments
$path
(string (opens new window), null (opens new window))$fetch
(boolean (opens new window))
Returns
# autosuggestFieldHtml()
- Since
- 3.7.0
Renders an autosuggest field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# 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']
.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# checkboxSelectFieldHtml()
- Since
- 3.6.0
Renders a checkbox select field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# colorFieldHtml()
- Since
- 3.6.0
Renders a color field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# dateFieldHtml()
- Since
- 4.0.0
Returns a date field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# dateHtml()
- Since
- 4.0.0
Returns a date input’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# dateTimeFieldHtml()
- Since
- 3.7.0
Renders a date + time field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# editableTableFieldHtml()
- Since
- 3.6.0
Renders an editable table field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# elementHtml()
- Since
- 3.5.8
Renders an element’s HTML.
View source (opens new window)
Arguments
$element
(craft\base\ElementInterface) – The element to be rendered$context
(string (opens new window)) – The context the element is going to be shown in (index
,field
, etc.)$size
(string (opens new window)) – The size of the element (small
orlarge
)$inputName
(string (opens new window), null (opens new window)) – Thename
attribute that should be set on the hidden input, if$context
is set tofield
$showStatus
(boolean (opens new window)) – Whether the element status should be shown (if the element type has statuses)$showThumb
(boolean (opens new window)) – Whether the element thumb should be shown (if the element has one)$showLabel
(boolean (opens new window)) – Whether the element label should be shown$showDraftName
(boolean (opens new window)) – Whether to show the draft name beside the label if the element is a draft of a published element$single
(boolean (opens new window)) – Whether the input name should omit the trailing[]
$autoReload
(boolean (opens new window)) – Whether the element should auto-reload itself when it’s saved
Returns
# elementPreviewHtml()
- Since
- 3.6.3
Returns element preview HTML, for a list of elements.
View source (opens new window)
Arguments
$elements
(craft\base\ElementInterface[]) – The elements$size
(string (opens new window)) – The size of the element (small
orlarge
)$showStatus
(boolean (opens new window)) – Whether the element status should be shown (if the element type has statuses)$showThumb
(boolean (opens new window)) – Whether the element thumb should be shown (if the element has one)$showLabel
(boolean (opens new window)) – Whether the element label should be shown$showDraftName
(boolean (opens new window)) – 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.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# elementSelectHtml()
- Since
- 4.0.0
Renders an element select input’s HTML
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# fieldHtml()
- Since
- 3.5.8
Renders a field’s HTML, for the given input HTML or a template.
View source (opens new window)
Arguments
$input
(string (opens new window)) – The input HTML or template path. If passing a template path, it must begin withtemplate:
.$config
(array (opens new window))
Returns
Throws
- craft\web\twig\TemplateLoaderException
if $input begins withtemplate:
and is followed by an invalid template path - yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# fieldLayoutDesignerHtml()
- Since
- 4.0.0
Renders a field layout designer.
View source (opens new window)
Arguments
$fieldLayout
(craft\models\FieldLayout)$config
(array (opens new window))
Returns
# lightswitchFieldHtml()
- Since
- 3.6.0
Renders a lightswitch field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# lightswitchHtml()
- Since
- 4.0.0
Renders a lightswitch input’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# metadataHtml()
Returns a metadata component’s HTML.
View source (opens new window)
Arguments
$data
(array (opens new window)) – The data, with keys representing the labels. The values can either be strings or callables. If a value isfalse
, it will be omitted.
Returns
# multiSelectFieldHtml()
- Since
- 4.0.0
Renders a multi-select field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# multiSelectHtml()
- Since
- 4.0.0
Renders a multi-select input.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
# renderTemplate()
Renders a control panel template.
View source (opens new window)
Arguments
$template
(string (opens new window))$variables
(array (opens new window))
Returns
Throws
- craft\web\twig\TemplateLoaderException
if$template
is 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.
View source (opens new window)
Returns
craft\models\Site, null (opens new window) – The site, or null
if the user doesn’t have permission to edit any sites.
# selectFieldHtml()
- Since
- 3.6.0
Renders a select field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# selectHtml()
- Since
- 3.6.0
Renders a select input.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
# selectizeFieldHtml()
- Since
- 4.0.0
Renders a selectize field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# selectizeHtml()
- Since
- 4.0.0
Renders a selectize input.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
# textFieldHtml()
- Since
- 3.6.0
Renders a text field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# textHtml()
- Since
- 4.0.0
Renders a text input’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# textareaFieldHtml()
- Since
- 3.6.0
Renders a textarea field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# textareaHtml()
- Since
- 4.0.0
Renders a textarea input’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# timeFieldHtml()
- Since
- 4.0.0
Returns a date field’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# timeHtml()
- Since
- 4.0.0
Returns a time input’s HTML.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$config['siteId']
is invalid
# Constants
Constant | Description |
---|---|
ELEMENT_SIZE_LARGE | |
ELEMENT_SIZE_SMALL |
# Events
# EVENT_DEFINE_ELEMENT_INNER_HTML
- 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.