Final Class Yiisoft\Yii\Widgets\Alert
| Inheritance | Yiisoft\Yii\Widgets\Alert » Yiisoft\Widget\Widget |
|---|
Alert renders an alert component.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| attributes() | Returns a new instance with the HTML attributes. | Yiisoft\Yii\Widgets\Alert |
| body() | Returns a new instance with changed message body. | Yiisoft\Yii\Widgets\Alert |
| bodyAttributes() | Returns a new instance with the HTML attributes for the message body tag. | Yiisoft\Yii\Widgets\Alert |
| bodyClass() | Returns a new instance with CSS class for the message body tag. | Yiisoft\Yii\Widgets\Alert |
| bodyContainer() | Returns a new instance specifying when allows you to add an extra wrapper for the panel body. | Yiisoft\Yii\Widgets\Alert |
| bodyContainerAttributes() | Returns a new instance with the HTML attributes for rendering extra message wrapper. | Yiisoft\Yii\Widgets\Alert |
| bodyContainerClass() | Returns a new instance with the CSS class for extra message wrapper. | Yiisoft\Yii\Widgets\Alert |
| bodyTag() | Returns a new instance specifying when allows you to add an extra wrapper for the message body. | Yiisoft\Yii\Widgets\Alert |
| buttonAttributes() | Returns a new instance with the HTML the attributes for rendering the button tag. | Yiisoft\Yii\Widgets\Alert |
| buttonClass() | Returns a new instance with the CSS class for the button. | Yiisoft\Yii\Widgets\Alert |
| buttonLabel() | Returns a new instance with the label for the button. | Yiisoft\Yii\Widgets\Alert |
| buttonOnClick() | Returns a new instance with the onclick JavaScript for the button. |
Yiisoft\Yii\Widgets\Alert |
| class() | Returns a new instance with the CSS class for the widget. | Yiisoft\Yii\Widgets\Alert |
| header() | Returns a new instance with the header content. | Yiisoft\Yii\Widgets\Alert |
| headerAttributes() | Returns a new instance with the HTML attributes for rendering the header content. | Yiisoft\Yii\Widgets\Alert |
| headerClass() | Returns a new instance with the CSS class for the header. | Yiisoft\Yii\Widgets\Alert |
| headerContainer() | Returns a new instance specifying when allows you to add a div tag to the header extra wrapper. | Yiisoft\Yii\Widgets\Alert |
| headerContainerAttributes() | Returns a new instance with the HTML attributes for rendering the header. | Yiisoft\Yii\Widgets\Alert |
| headerContainerClass() | Returns a new instance with the CSS class for the header extra wrapper. | Yiisoft\Yii\Widgets\Alert |
| headerTag() | Returns a new instance with the tag name for the header. | Yiisoft\Yii\Widgets\Alert |
| iconAttributes() | Returns a new instance with the HTML attributes for rendering the <i> tag for the icon. |
Yiisoft\Yii\Widgets\Alert |
| iconClass() | Returns a new instance with the icon CSS class. | Yiisoft\Yii\Widgets\Alert |
| iconContainerAttributes() | Returns a new instance with the HTML attributes for rendering icon container. | Yiisoft\Yii\Widgets\Alert |
| iconContainerClass() | Returns a new instance with the CSS class for the icon container. | Yiisoft\Yii\Widgets\Alert |
| iconText() | Returns a new instance with the icon text. | Yiisoft\Yii\Widgets\Alert |
| id() | Returns a new instance with the specified Widget ID. | Yiisoft\Yii\Widgets\Alert |
| layoutBody() | Returns a new instance with the config layout body. | Yiisoft\Yii\Widgets\Alert |
| layoutHeader() | Returns a new instance with the config layout header. | Yiisoft\Yii\Widgets\Alert |
| render() | Yiisoft\Yii\Widgets\Alert |
Method Details
Returns a new instance with the HTML attributes.
| public self attributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. |
public function attributes(array $valuesMap): self
{
$new = clone $this;
$new->attributes = $valuesMap;
return $new;
}
Returns a new instance with changed message body.
| public self body ( string $value ) | ||
| $value | string |
The message body. |
public function body(string $value): self
{
$new = clone $this;
$new->body = $value;
return $new;
}
Returns a new instance with the HTML attributes for the message body tag.
| public self bodyAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered. |
public function bodyAttributes(array $valuesMap): self
{
$new = clone $this;
$new->bodyAttributes = $valuesMap;
return $new;
}
Returns a new instance with CSS class for the message body tag.
| public self bodyClass ( string $value ) | ||
| $value | string |
The CSS class name. |
public function bodyClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->bodyAttributes, $value);
return $new;
}
Returns a new instance specifying when allows you to add an extra wrapper for the panel body.
| public self bodyContainer ( boolean $value ) | ||
| $value | boolean |
Whether to add an extra wrapper for the panel body. |
public function bodyContainer(bool $value): self
{
$new = clone $this;
$new->bodyContainer = $value;
return $new;
}
Returns a new instance with the HTML attributes for rendering extra message wrapper.
| public self bodyContainerAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered. |
public function bodyContainerAttributes(array $valuesMap): self
{
$new = clone $this;
$new->bodyContainerAttributes = $valuesMap;
return $new;
}
Returns a new instance with the CSS class for extra message wrapper.
| public self bodyContainerClass ( string $value ) | ||
| $value | string |
The CSS class name. |
public function bodyContainerClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->bodyContainerAttributes, $value);
return $new;
}
Returns a new instance specifying when allows you to add an extra wrapper for the message body.
| public self bodyTag ( string|null $tag = null ) | ||
| $tag | string|null |
The tag name. |
public function bodyTag(?string $tag = null): self
{
if ($tag === '') {
throw new InvalidArgumentException('Body tag must be a string and cannot be empty.');
}
$new = clone $this;
$new->bodyTag = $tag;
return $new;
}
Returns a new instance with the CSS class for the widget.
| public self class ( string $value ) | ||
| $value | string |
The CSS class name. |
public function class(string $value): self
{
$new = clone $this;
Html::addCssClass($new->attributes, $value);
return $new;
}
Returns a new instance with the header content.
| public self header ( string $value ) | ||
| $value | string |
The header content in the message. |
public function header(string $value): self
{
$new = clone $this;
$new->header = $value;
return $new;
}
Returns a new instance with the HTML attributes for rendering the header content.
| public self headerAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered. |
public function headerAttributes(array $valuesMap): self
{
$new = clone $this;
$new->headerAttributes = $valuesMap;
return $new;
}
Returns a new instance with the CSS class for the header.
| public self headerClass ( string $value ) | ||
| $value | string |
The CSS class name. |
public function headerClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->headerAttributes, $value);
return $new;
}
Returns a new instance specifying when allows you to add a div tag to the header extra wrapper.
| public self headerContainer ( boolean $value = true ) | ||
| $value | boolean |
The value indicating whether to add a div tag to the header extra wrapper. |
public function headerContainer(bool $value = true): self
{
$new = clone $this;
$new->headerContainer = $value;
return $new;
}
Returns a new instance with the HTML attributes for rendering the header.
| public self headerContainerAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered. |
public function headerContainerAttributes(array $valuesMap): self
{
$new = clone $this;
$new->headerContainerAttributes = $valuesMap;
return $new;
}
Returns a new instance with the CSS class for the header extra wrapper.
| public self headerContainerClass ( string $value ) | ||
| $value | string |
The CSS class name. |
public function headerContainerClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->headerContainerAttributes, $value);
return $new;
}
Returns a new instance with the tag name for the header.
| public self headerTag ( string $value ) | ||
| $value | string |
The tag name for the header. |
| throws | InvalidArgumentException | |
|---|---|---|
public function headerTag(string $value): self
{
if (empty($value)) {
throw new InvalidArgumentException('Header tag must be a string and cannot be empty.');
}
$new = clone $this;
$new->headerTag = $value;
return $new;
}
Returns a new instance with the HTML attributes for rendering the <i> tag for the icon.
| public self iconAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered. |
public function iconAttributes(array $valuesMap): self
{
$new = clone $this;
$new->iconAttributes = $valuesMap;
return $new;
}
Returns a new instance with the icon CSS class.
| public self iconClass ( string $value ) | ||
| $value | string |
The icon CSS class. |
public function iconClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->iconAttributes, $value);
return $new;
}
Returns a new instance with the HTML attributes for rendering icon container.
The rest of the options will be rendered as the HTML attributes of the icon container.
| public self iconContainerAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered. |
public function iconContainerAttributes(array $valuesMap): self
{
$new = clone $this;
$new->iconContainerAttributes = $valuesMap;
return $new;
}
Returns a new instance with the CSS class for the icon container.
| public self iconContainerClass ( string $value ) | ||
| $value | string |
The CSS class name. |
public function iconContainerClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->iconContainerAttributes, $value);
return $new;
}
Returns a new instance with the icon text.
| public self iconText ( string $value ) | ||
| $value | string |
The icon text. |
public function iconText(string $value): self
{
$new = clone $this;
$new->iconText = $value;
return $new;
}
Returns a new instance with the specified Widget ID.
| public self id ( string $value ) | ||
| $value | string |
The id of the widget. |
public function id(string $value): self
{
$new = clone $this;
$new->attributes['id'] = $value;
return $new;
}
Returns a new instance with the config layout body.
| public self layoutBody ( string $value ) | ||
| $value | string |
The config layout body. |
public function layoutBody(string $value): self
{
$new = clone $this;
$new->layoutBody = $value;
return $new;
}
Returns a new instance with the config layout header.
| public self layoutHeader ( string $value ) | ||
| $value | string |
The config layout header. |
public function layoutHeader(string $value): self
{
$new = clone $this;
$new->layoutHeader = $value;
return $new;
}
| public string render ( ) |
public function render(): string
{
$div = Div::tag();
$parts = [];
if (!array_key_exists('id', $this->attributes)) {
$div = $div->id(Html::generateId('alert-'));
}
$parts['{button}'] = $this->renderButton();
$parts['{icon}'] = $this->renderIcon();
$parts['{body}'] = $this->renderBody();
$parts['{header}'] = $this->renderHeader();
$contentAlert = $this->renderHeaderContainer($parts) . PHP_EOL . $this->renderBodyContainer($parts);
return $this->body !== ''
? $div
->attribute('role', 'alert')
->addAttributes($this->attributes)
->content(PHP_EOL . trim($contentAlert) . PHP_EOL)
->encode(false)
->render()
: '';
}
Signup or Login in order to comment.