Legacy Documentation
You are using the documentation for version 3.5.17. Go here for the latest version or check here for your available upgrades to the latest version.
CP/Alert Service¶
Simple Example¶
Alerts are for providing feedback on an action and calling attention to warnings or errors. We describe, in detail, how to build different kinds of alerts in our CP style-guide. We have also created an Alert Service for creating alerts in your code. For example:
ee('CP/Alert')->makeInline('fortune-cookie-form')
->asIssue()
->withTitle(lang('fortune_cookie_save_error'))
->addToBody(lang('fortune_cookie_save_error_desc'))
->now();
CP/Alert Service Methods¶
-
class
EllisLab\ExpressionEngine\Service\Alert\
AlertCollection
¶
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
make
($name, $type = 'inline')¶ Makes a new named alert of the specified type.
Parameters: - $name (string) – The name of the alert
- $type (string) – The type of the alert (‘inline’, ‘banner’, or ‘standard’)
Returns: An alert
Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
makeInline
($name)¶ Makes a new named inline alert.
Parameters: - $name (string) – The name of the alert
Returns: An alert
Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
makeBanner
($name)¶ Makes a new named banner alert.
Parameters: - $name (string) – The name of the alert
Returns: An alert
Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
makeStandard
($name)¶ Makes a new named standard alert.
Parameters: - $name (string) – The name of the alert
Returns: An alert
Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
get
($name, $type = 'inline')¶ Gets the rendered value of a named alert of a certain type.
Parameters: - $name (string) – The name of the alert
- $type (string) – The type of the alert (‘inline’, ‘banner’, or ‘standard’)
Returns: The rendered HTML of the alert
Return type: String
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
getAllBanners
()¶ Gets the rendered value of all banner alerts.
Returns: The rendered HTML of the alert Return type: String
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
getAllInlines
()¶ Gets the rendered value of all inline alerts.
Returns: The rendered HTML of the alert Return type: String
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
getStandard
()¶ Gets the rendered value of the standard alert.
Returns: The rendered HTML of the alert Return type: String
Alert Object Methods¶
-
EllisLab\ExpressionEngine\Service\Alert\Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
asIssue
()¶ Marks the alert as an issue alert.
Returns: $this Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
asWarning
()¶ Marks the alert as a warning alert.
Returns: $this Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
asSuccess
()¶ Marks the alert as a success alert.
Returns: $this Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
withTitle
($title)¶ Sets the title of the alert.
Parameters: - $title (string) – The title of the alert
Returns: $this
Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
addToBody
($item, $class = NULL)¶ Adds content to the body of the alert.
Parameters: - $item (string|array) – The item to display. If it’s an array it will be rendred as a list.
- $class (string) – An optional CSS class to add to the item
Returns: $this
Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
addSeparator
()¶ Adds a separator to the body of the alert.
Returns: $this Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
setSubAlert
($alert)¶ Adds an alert to the alert.
Parameters: - $alert (string) – An alert to render in this alert
Returns: $this
Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
canClose
()¶ Allows the alert to be closed by rendering a close icon.
Returns: $this Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
cannotClose
()¶ Does not render a close icon in the alert.
Returns: $this Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
render
()¶ Renders the alert to HTML
Returns: The rendered HTML of the alert. Return type: String
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
defer
()¶ Defers rendering and displaying of the alert until the next control panel request.
Returns: $this Return type: Alert
-
EllisLab\ExpressionEngine\Service\Alert\AlertCollection::
now
()¶ Saves the alert to be rendered and displayed during this request.
Returns: $this Return type: Alert