├── .github
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE.md
├── PULL_REQUEST_TEMPLATE.md
└── stale.yml
├── CHANGE.md
├── LICENSE.md
├── README.md
├── composer.json
└── src
├── Alert.php
├── AlertAsset.php
├── AlertBlock.php
├── AlertInterface.php
├── AlertMethodsTrait.php
├── AlertTrait.php
├── Bs3Alert.php
├── Bs4Alert.php
├── Bs5Alert.php
└── assets
└── css
├── alert.css
└── alert.min.css
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing to yii2-widget-alert
2 | =================================
3 | Looking to contribute something to yii2-widget-alert? **Here's how you can help.**
4 |
5 | Please take a moment to review this document in order to make the contribution
6 | process easy and effective for everyone involved.
7 |
8 | Following these guidelines helps to communicate that you respect the time of
9 | the developers managing and developing this open source project. In return,
10 | they should reciprocate that respect in addressing your issue or assessing
11 | patches and features.
12 |
13 | Using the issue tracker
14 | -----------------------
15 | When [reporting bugs][reporting-bugs] or
16 | [requesting features][requesting-features], the
17 | [issue tracker on GitHub][issue-tracker] is the recommended channel to use.
18 |
19 | The issue tracker **is not** a place for support requests. Refer the
20 | [extension documentation and demos](http://demos.krajee.com/widget-details/alert) and/or refer to the
21 | [webtips Q & A forum](http://webtips.krajee.com/questions) which are the better places to get help.
22 |
23 | Reporting bugs with yii2-widget-alert
24 | -------------------------------------
25 | We really appreciate clear bug reports that _consistently_ show an issue
26 | _within yii2-widget-alert_.
27 |
28 | The ideal bug report follows these guidelines:
29 |
30 | 1. **Use the [GitHub issue search][issue-search]** — Check if the issue
31 | has already been reported.
32 | 2. **Check if the issue has been fixed** — Try to reproduce the problem
33 | using the code in the `master` branch.
34 | 3. **Isolate the problem** — Try to share a demo or a test case that
35 | consistently reproduces the problem.
36 |
37 | Please try to be as detailed as possible in your bug report, especially if an
38 | isolated test case cannot be made. Some useful questions to include the answer
39 | to are:
40 |
41 | - What steps can be used to reproduce the issue?
42 | - What is the bug and what is the expected outcome?
43 | - What browser(s) and Operating System have you tested with?
44 | - Does the bug happen consistently across all tested browsers?
45 | - What version of jQuery are you using? And what version of yii2-widget-alert?
46 | - Are you using yii2-widget-alert with other plugins?
47 |
48 | All of these questions will help others fix and identify any potential bugs.
49 |
50 | Requesting features in yii2-widget-alert
51 | ----------------------------------------
52 | Before starting work on a major feature for yii2-widget-alert, **read the
53 | [documentation](http://demos.krajee.com/widget-details/alert) first** or you may risk spending a considerable amount of
54 | time on something which the project developers are not interested in bringing into the project.
55 |
56 | ### Submitting a pull request
57 |
58 | We use GitHub's pull request system for submitting patches. Here are some
59 | guidelines to follow when creating the pull request for your fix.
60 |
61 | 1. Make sure to create a ticket for your pull request. This will serve as the
62 | bug ticket, and any discussion about the bug will take place there. Your pull
63 | request will be focused on the specific changes that fix the bug.
64 | 2. Make sure to reference the ticket you are fixing within your pull request.
65 | This will allow us to close off the ticket once we merge the pull request, or
66 | follow up on the ticket if there are any related blocking issues.
67 | 3. Explain why the specific change was made. Not everyone who is reviewing your
68 | pull request will be familiar with the problem it is fixing.
69 | 4. Run your tests first. If your tests aren't passing, the pull request won't
70 | be able to be merged. If you're breaking existing tests, make sure that you
71 | aren't causing any breaking changes.
72 | 5. Only include source changes. While it's not required, only including changes
73 | from the `src` directory will prevent merge conflicts from occuring. Making
74 | this happen can be as a simple as not committing changes from the `dist`
75 | directory.
76 |
77 | By following these steps, you will make it easier for your pull request to be
78 | reviewed and eventually merged.
79 |
80 | Triaging issues and pull requests
81 | ---------------------------------
82 | Anyone can help the project maintainers triage issues and review pull requests.
83 |
84 | ### Handling new issues
85 |
86 | yii2-widget-alert regularly receives new issues which need to be tested and organized.
87 |
88 | When a new issue that comes in that is similar to another existing issue, it
89 | should be checked to make sure it is not a duplicate. Duplicates issues should
90 | be marked by replying to the issue with "Duplicate of #[issue number]" where
91 | `[issue number]` is the url or issue number for the existing issue. This will
92 | allow the project maintainers to quickly close off additional issues and keep
93 | the discussion focused within a single issue.
94 |
95 | If you can test issues that are reported to yii2-widget-alert that contain test cases and
96 | confirm under what conditions bugs happen, that will allow others to identify
97 | what causes a bug quicker.
98 |
99 | ### Reviewing pull requests
100 |
101 | It is very common for pull requests to be opened for issues that contain a clear
102 | solution to the problem. These pull requests should be rigorously reviewed by
103 | the community before being accepted. If you are not sure about a piece of
104 | submitted code, or know of a better way to do something, do not hesitate to make
105 | a comment on the pull request.
106 |
107 | ### Reviving old tickets
108 |
109 | If you come across tickets which have not been updated for a while, you are
110 | encouraged to revive them. While this can be as simple as saying `:+1:`, it is
111 | best if you can include more information on the issue. Common bugs and feature
112 | requests are more likely to be fixed, whether it is by the community or the
113 | developers, so keeping tickets up to date is encouraged.
114 |
115 | Licensing
116 | ---------
117 |
118 | It should also be made clear that **all code contributed to yii2-widget-alert** must be
119 | licensable under the [BSD-3 license][licensing]. Code that cannot be released
120 | under this license **cannot be accepted** into the project.
121 |
122 | [issue-search]: https://github.com/kartik-v/yii2-widget-alert/search?q=&type=Issues
123 | [issue-tracker]: https://github.com/kartik-v/yii2-widget-alert/issues
124 | [licensing]: https://github.com/kartik-v/yii2-widget-alert/blob/master/LICENSE.md
125 | [reporting-bugs]: #reporting-bugs-with-yii2-widget-alert
126 | [requesting-features]: #requesting-features-in-yii2-widget-alert
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Prerequisites
2 |
3 | - [ ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
4 | - [ ] The issue still exists against the latest `master` branch of yii2-widget-alert.
5 | - [ ] This is not an usage question. I confirm having gone through and read the [documentation and demos](http://demos.krajee.com/widget-details/alert).
6 | - [ ] This is not a general programming / coding question. (Those should be directed to the [webtips Q & A forum](http://webtips.krajee.com/questions)).
7 | - [ ] I have attempted to find the simplest possible steps to reproduce the issue.
8 | - [ ] I have included a failing test as a pull request (Optional).
9 |
10 | ## Steps to reproduce the issue
11 |
12 | 1.
13 | 2.
14 | 3.
15 |
16 | ## Expected behavior and actual behavior
17 |
18 | When I follow those steps, I see...
19 |
20 | I was expecting...
21 |
22 | ## Environment
23 |
24 | #### Browsers
25 |
26 | - [ ] Google Chrome
27 | - [ ] Mozilla Firefox
28 | - [ ] Internet Explorer
29 | - [ ] Safari
30 |
31 | #### Operating System
32 |
33 | - [ ] Windows
34 | - [ ] Mac OS X
35 | - [ ] Linux
36 | - [ ] Mobile
37 |
38 | #### Libraries
39 |
40 | - jQuery version:
41 | - yii2-widget-alert version:
42 |
43 | ## Isolating the problem
44 |
45 | - [ ] This bug happens [on the demos page](http://demos.krajee.com/widget-details/alert)
46 | - [ ] The bug happens consistently across all tested browsers
47 | - [ ] This bug happens when using yii2-widget-alert without other plugins.
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Scope
2 | This pull request includes a
3 |
4 | - [ ] Bug fix
5 | - [ ] New feature
6 | - [ ] Translation
7 |
8 | ## Changes
9 | The following changes were made (this change is also documented in the [change log](https://github.com/kartik-v/yii2-widget-alert/blob/master/CHANGE.md)):
10 |
11 | -
12 | -
13 | -
14 |
15 | ## Related Issues
16 | If this is related to an existing ticket, include a link to it as well.
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Number of days of inactivity before an issue becomes stale
2 | daysUntilStale: 60
3 | # Number of days of inactivity before a stale issue is closed
4 | daysUntilClose: 7
5 | # Issues with these labels will never be considered stale
6 | exemptLabels:
7 | - bug
8 | - enhancement
9 | - pinned
10 | - security
11 | # Label to use when marking an issue as stale
12 | staleLabel: wontfix
13 | # Comment to post when marking an issue as stale. Set to `false` to disable
14 | markComment: >
15 | This issue has been automatically marked as stale because it has not had
16 | recent activity. It will be closed if no further activity occurs. Thank you
17 | for your contributions.
18 | # Comment to post when closing a stale issue. Set to `false` to disable
19 | closeComment: false
--------------------------------------------------------------------------------
/CHANGE.md:
--------------------------------------------------------------------------------
1 | Change Log: `yii2-widget-alert`
2 | ===============================
3 |
4 | ## Version 1.1.5
5 |
6 | **Date:** 16-Oct-2021
7 |
8 | - Enhancements for Bootstrap 5.x support.
9 |
10 | ## Version 1.1.4
11 |
12 | **Date:** 02-Jun-2020
13 |
14 | - (bug #23, #24): Correct `AlertBlock` base widget class.
15 | - (bug #21): Correct yii2-widget-growl dependency.
16 |
17 | ## Version 1.1.3
18 |
19 | **Date:** 09-Mar-2020
20 |
21 | - Eliminate redundant class BaseAlert.
22 |
23 | ## Version 1.1.2
24 |
25 | **Date:** 29-Jan-2020
26 |
27 | - Enhancements to support both Bootstrap 4.x & 3.x.
28 | - Move all source code to `src` directory.
29 |
30 | ## Version 1.1.1
31 |
32 | **Date:** 10-Mar-2017
33 |
34 | - enh #2, #8, #11, #12: Allow multiple messages of same type.
35 | - Add github contribution and PR templates.
36 | - Add composer branch alias to allow getting latest `dev-master` updates.
37 |
38 | ## Version 1.1.0
39 |
40 | **Date:** 19-Nov-2014
41 |
42 | - bug #1: Fix dependency on \kartik\growl\Growl
43 |
44 | ## Version 1.0.0
45 |
46 | **Date:** 08-Nov-2014
47 |
48 | - Initial release
49 | - Sub repo split from [yii2-widgets](https://github.com/kartik-v/yii2-widgets)
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 - 2021, Kartik Visweswaran
2 | Krajee.com
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | * Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | * Neither the names of Kartik Visweswaran or Krajee nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | yii2-widget-alert
7 |
8 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | [](https://packagist.org/packages/kartik-v/yii2-widget-alert)
17 | [](https://packagist.org/packages/kartik-v/yii2-widget-alert)
18 | [](https://packagist.org/packages/kartik-v/yii2-widget-alert)
19 | [](https://packagist.org/packages/kartik-v/yii2-widget-alert)
20 | [](https://packagist.org/packages/kartik-v/yii2-widget-alert)
21 | [](https://packagist.org/packages/kartik-v/yii2-widget-alert)
22 |
23 |
24 |
25 | This extension contains a couple of useful widgets. The `Alert` widget extends the `\yii\bootstrap\Alert` widget with more easy styling and auto fade out options. In addition, it includes a `AlertBlock` widget that groups multiple `\kartik\widget\Alert` or `kartik\widget\Growl` widgets in one single block and renders them stacked vertically on the current page.
26 | You can choose the `TYPE_ALERT` style or the `TYPE_GROWL` style for your notifications. You can also set the widget to automatically read and display session flash
27 | messages (which is the default setting). Alternatively, you can setup and configure your own block of custom alerts.
28 |
29 | > NOTE: This extension is a sub repo split of [yii2-widgets](https://github.com/kartik-v/yii2-widgets). The split has been done since 08-Nov-2014 to allow developers to install this specific widget in isolation if needed. One can also use the extension the previous way with the whole suite of [yii2-widgets](http://demos.krajee.com/widgets).
30 |
31 | ## Installation
32 |
33 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). Check the [composer.json](https://github.com/kartik-v/yii2-widget-alert/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json.
34 |
35 | To install, either run
36 |
37 | ```
38 | $ php composer.phar require kartik-v/yii2-widget-alert "*"
39 | ```
40 |
41 | or add
42 |
43 | ```
44 | "kartik-v/yii2-widget-alert": "*"
45 | ```
46 |
47 | to the ```require``` section of your `composer.json` file.
48 |
49 | > NOTE: Using Growl is optional and it is not automatically installed with this extension. If you want to use it in your project, you need to either run
50 | ```
51 | $ php composer.phar require kartik-v/yii2-widget-growl "*"
52 | ```
53 | or add
54 | ```
55 | "kartik-v/yii2-widget-growl": "*"
56 | ```
57 | to the `require` section of your `composer.json` file.
58 |
59 | > Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-widget-alert/blob/master/CHANGE.md) for details on changes to various releases.
60 |
61 | ## Demo
62 |
63 | You can refer detailed documentation and demos for [Alert](http://demos.krajee.com/widget-details/alert) and [AlertBlock](http://demos.krajee.com/widget-details/alert-block) widgets on usage of the extension.
64 |
65 | ## Usage
66 |
67 | ### Alert
68 | ```php
69 | use kartik\alert\Alert;
70 |
71 | echo Alert::widget([
72 | 'type' => Alert::TYPE_INFO,
73 | 'title' => 'Note',
74 | 'titleOptions' => ['icon' => 'info-sign'],
75 | 'body' => 'This is an informative alert'
76 | ]);
77 | ```
78 |
79 | ### AlertBlock
80 | ```php
81 | use kartik\alert\AlertBlock;
82 |
83 | echo AlertBlock::widget([
84 | 'type' => AlertBlock::TYPE_ALERT,
85 | 'useSessionFlash' => true
86 | ]);
87 | ```
88 |
89 | ## License
90 |
91 | **yii2-widget-alert** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.
92 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "kartik-v/yii2-widget-alert",
3 | "description": "A widget to generate alert based notifications using bootstrap-alert plugin (sub repo split from yii2-widgets)",
4 | "keywords": [
5 | "yii2",
6 | "extension",
7 | "widget",
8 | "alert",
9 | "flash",
10 | "block",
11 | "notification",
12 | "bootstrap",
13 | "jquery",
14 | "plugin"
15 | ],
16 | "homepage": "https://github.com/kartik-v/yii2-widget-alert",
17 | "type": "yii2-extension",
18 | "license": "BSD-3-Clause",
19 | "authors": [
20 | {
21 | "name": "Kartik Visweswaran",
22 | "email": "kartikv2@gmail.com",
23 | "homepage": "http://www.krajee.com/"
24 | }
25 | ],
26 | "require": {
27 | "kartik-v/yii2-widget-growl": ">=1.1.2"
28 | },
29 | "autoload": {
30 | "psr-4": {
31 | "kartik\\alert\\": "src"
32 | }
33 | },
34 | "extra": {
35 | "branch-alias": {
36 | "dev-master": "1.1.x-dev"
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Alert.php:
--------------------------------------------------------------------------------
1 |
20 | * @since 1.0
21 | */
22 | class Alert extends Widget implements AlertInterface
23 | {
24 | use AlertTrait;
25 |
26 | /**
27 | * @var string the body content in the alert component. Note that anything between the [[begin()]] and [[end()]]
28 | * calls of the Alert widget will also be treated as the body content, and will be rendered before this.
29 | */
30 | public $body;
31 |
32 | /**
33 | * @var array|false the options for rendering the close button tag. The close button is displayed in the header of
34 | * the modal window. Clicking on the button will hide the modal window. If this is false, no close button will be
35 | * rendered.
36 | *
37 | * The following special options are supported:
38 | *
39 | * - tag: string, the tag name of the button. Defaults to 'button'.
40 | * - label: string, the label of the button. Defaults to '×'.
41 | *
42 | * The rest of the options will be rendered as the HTML attributes of the button tag. Please refer to the
43 | * [Alert documentation](http://getbootstrap.com/components/#alerts) for the supported HTML attributes.
44 | */
45 | public $closeButton = [];
46 |
47 | /**
48 | * @inheritdoc
49 | * @throws InvalidConfigException
50 | */
51 | public function run()
52 | {
53 | $opts = [
54 | 'type' => $this->type,
55 | 'body' => $this->body,
56 | 'closeButton' => $this->closeButton,
57 | 'iconType' => $this->iconType,
58 | 'icon' => $this->icon,
59 | 'iconOptions' => $this->iconOptions,
60 | 'title' => $this->title,
61 | 'titleOptions' => $this->titleOptions,
62 | 'showSeparator' => $this->showSeparator,
63 | 'clientOptions' => $this->pluginOptions,
64 | 'clientEvents' => $this->pluginEvents,
65 | 'options' => $this->options,
66 | ];
67 | if (isset($this->delay)) {
68 | $opts['delay'] = $this->delay;
69 | }
70 | /**
71 | * @var Widget $class
72 | */
73 | $class = '\\kartik\\alert\\Bs' . $this->getBsVer() . 'Alert';
74 | return $class::widget($opts);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/AlertAsset.php:
--------------------------------------------------------------------------------
1 |
18 | * @since 1.0
19 | */
20 | class AlertAsset extends AssetBundle
21 | {
22 | /**
23 | * @inheritdoc
24 | */
25 | public function init()
26 | {
27 | $this->setSourcePath(__DIR__ . '/assets');
28 | $this->setupAssets('css', ['css/alert']);
29 | parent::init();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/AlertBlock.php:
--------------------------------------------------------------------------------
1 |
26 | * @since 1.0
27 | */
28 | class AlertBlock extends Widget
29 | {
30 | /**
31 | * Default bootstrap alert style
32 | */
33 | const TYPE_ALERT = 'alert';
34 | /**
35 | * Bootstrap growl plugin alert style
36 | */
37 | const TYPE_GROWL = 'growl';
38 |
39 | /**
40 | * @var string the type of alert to use. Can be one of [[TYPE_ALERT]] or [[TYPE_GROWL]]. Defaults to [[TYPE_ALERT]].
41 | */
42 | public $type = self::TYPE_ALERT;
43 |
44 | /**
45 | * @var integer time in milliseconds to delay the fade out of each alert. If set to `0` or `false`, alerts
46 | * will never fade out and will be always displayed. This defaults to `2000` ms for [[TYPE_ALERT]] and
47 | * `1000` ms for [[TYPE_GROWL]].
48 | */
49 | public $delay;
50 |
51 | /**
52 | * @var boolean whether to automatically use messages set via `Yii::$app->session->setFlash()`. Defaults to `true`.
53 | * If set to `false`, you would need to pass the `body` setting within [[alertSetting]] array.
54 | */
55 | public $useSessionFlash = true;
56 |
57 | /**
58 | * @var array the alert types configuration for the alert messages. This array is setup as `$alert => $settings`,
59 | * where:
60 | *
61 | * - `$alert`: _string_, is the name of the session flash variable (e.g. `error`, `success`, `info`, `warning`).
62 | * - `$settings`: _array_, the [[Alert]] or [[Growl]] widget settings depending on the [[type]] set.
63 | */
64 | public $alertSettings = [];
65 |
66 | /**
67 | * @var array the options for rendering the close button tag. This will be overridden by the `closeButton` setting
68 | * within the [[alertSettings]] configuration.
69 | */
70 | public $closeButton = [];
71 |
72 | /**
73 | * @inheritdoc
74 | */
75 | public function init()
76 | {
77 | parent::init();
78 | $this->initOptions();
79 | echo Html::beginTag('div', $this->options) . "\n";
80 | }
81 |
82 | /**
83 | * @inheritdoc
84 | */
85 | public function run()
86 | {
87 | parent::run();
88 | if ($this->useSessionFlash) {
89 | $this->renderFlashAlerts();
90 | } else {
91 | $this->renderAlerts();
92 | }
93 | echo "\n" . Html::endTag('div');
94 | }
95 |
96 | /**
97 | * Initializes widget options and settings.
98 | *
99 | * @throws InvalidConfigException
100 | */
101 | protected function initOptions()
102 | {
103 | if ($this->type == self::TYPE_GROWL) {
104 | Config::checkDependency('growl\Growl', 'yii2-widget-growl', 'for rendering Growl notifications in the alert block');
105 | }
106 | if (empty($this->options['id'])) {
107 | $this->options['id'] = $this->getId();
108 | }
109 | if (!isset($this->delay)) {
110 | $this->delay = ($this->type == self::TYPE_ALERT) ? 2000 : 1200;
111 | }
112 | if (empty($this->alertSettings) && $this->type == self::TYPE_GROWL) {
113 | $this->alertSettings = [
114 | 'error' => ['type' => Growl::TYPE_DANGER],
115 | 'success' => ['type' => Growl::TYPE_SUCCESS],
116 | 'info' => ['type' => Growl::TYPE_INFO],
117 | 'warning' => ['type' => Growl::TYPE_WARNING],
118 | 'growl' => ['type' => Growl::TYPE_GROWL]
119 | ];
120 | } elseif (empty($this->alertSettings)) {
121 | $this->alertSettings = [
122 | 'error' => ['type' => Alert::TYPE_DANGER],
123 | 'success' => ['type' => Alert::TYPE_SUCCESS],
124 | 'info' => ['type' => Alert::TYPE_INFO],
125 | 'warning' => ['type' => Alert::TYPE_WARNING],
126 | 'primary' => ['type' => Alert::TYPE_PRIMARY],
127 | 'default' => ['type' => Alert::TYPE_DEFAULT]
128 | ];
129 | }
130 | }
131 |
132 | /**
133 | * Renders alerts from session flash settings.
134 | * @see [[\yii\web\Session::getAllFlashes()]]
135 | */
136 | public function renderFlashAlerts()
137 | {
138 | $type = ($this->type == self::TYPE_GROWL) ? self::TYPE_GROWL : self::TYPE_ALERT;
139 | $session = Yii::$app->getSession();
140 | $flashes = $session->getAllFlashes();
141 | $delay = $this->delay;
142 | foreach ($flashes as $alert => $config) {
143 | if (!empty($this->alertSettings[$alert])) {
144 | $messages = is_array($config) ? $config : [$config];
145 | foreach($messages as $message) {
146 | $settings = $this->alertSettings[$alert];
147 | $settings['body'] = $message;
148 | if (empty($settings['closeButton'])) {
149 | $settings['closeButton'] = $this->closeButton;
150 | }
151 | $settings['delay'] = $delay;
152 | $delay += $this->delay;
153 | echo ($type == self::TYPE_GROWL) ? Growl::widget($settings) : Alert::widget($settings);
154 | }
155 | $session->removeFlash($alert);
156 | }
157 | }
158 | }
159 |
160 | /**
161 | * Renders manually set alerts
162 | */
163 | public function renderAlerts()
164 | {
165 | $type = ($this->type == self::TYPE_GROWL) ? self::TYPE_GROWL : self::TYPE_ALERT;
166 | foreach ($this->alertSettings as $alert => $settings) {
167 | if (!empty($settings['body'])) {
168 | echo ($type == self::TYPE_GROWL) ? Growl::widget($settings) : Alert::widget($settings);
169 | }
170 | }
171 | }
172 |
173 | /**
174 | * Renders the close button.
175 | *
176 | * @return string the rendering result
177 | */
178 | protected function renderCloseButton()
179 | {
180 | if ($this->closeButton !== null) {
181 | $tag = ArrayHelper::remove($this->closeButton, 'tag', 'button');
182 | $label = ArrayHelper::remove($this->closeButton, 'label', '×');
183 | if ($tag === 'button' && !isset($this->closeButton['type'])) {
184 | $this->closeButton['type'] = 'button';
185 | }
186 |
187 | return Html::tag($tag, $label, $this->closeButton);
188 | } else {
189 | return null;
190 | }
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/src/AlertInterface.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 1.0
17 | */
18 | interface AlertInterface
19 | {
20 | /**
21 | * information alert
22 | */
23 | const TYPE_INFO = 'alert-info';
24 | /**
25 | * danger/error alert
26 | */
27 | const TYPE_DANGER = 'alert-danger';
28 | /**
29 | * success alert
30 | */
31 | const TYPE_SUCCESS = 'alert-success';
32 | /**
33 | * warning alert
34 | */
35 | const TYPE_WARNING = 'alert-warning';
36 | /**
37 | * primary alert
38 | */
39 | const TYPE_PRIMARY = 'bg-primary';
40 | /**
41 | * default alert
42 | */
43 | const TYPE_DEFAULT = 'well';
44 | /**
45 | * custom alert
46 | */
47 | const TYPE_CUSTOM = 'alert-custom';
48 | }
49 |
--------------------------------------------------------------------------------
/src/AlertMethodsTrait.php:
--------------------------------------------------------------------------------
1 |
20 | * @since 1.0
21 | */
22 | trait AlertMethodsTrait
23 | {
24 | use AlertTrait;
25 |
26 | /**
27 | * @inheritdoc
28 | */
29 | public function run()
30 | {
31 | echo $this->getTitle();
32 | parent::run();
33 | }
34 |
35 | /**
36 | * Gets the title section
37 | *
38 | * @return string
39 | */
40 | protected function getTitle()
41 | {
42 | $icon = '';
43 | $title = '';
44 | $separator = '';
45 | if (!empty($this->icon) && $this->iconType == 'image') {
46 | $icon = Html::img($this->icon, $this->iconOptions);
47 | } elseif (!empty($this->icon)) {
48 | $this->iconOptions['class'] = $this->icon . ' ' . (empty($this->iconOptions['class']) ? 'kv-alert-title' :
49 | $this->iconOptions['class']);
50 | $icon = Html::tag('span', '', $this->iconOptions) . ' ';
51 | }
52 | if (!empty($this->title)) {
53 | if (empty($this->titleOptions['class'])) {
54 | $this->titleOptions['class'] = 'kv-alert-title';
55 | }
56 | $tag = ArrayHelper::remove($this->titleOptions, 'tag', 'span');
57 | $title = Html::tag($tag, $this->title, $this->titleOptions);
58 | if ($this->showSeparator) {
59 | $separator = '
' . "\n";
60 | }
61 | }
62 | return $icon . $title . $separator;
63 | }
64 |
65 | /**
66 | * @inheritdoc
67 | */
68 | protected function initOptions()
69 | {
70 | parent::initOptions();
71 | if (empty($this->options['id'])) {
72 | $this->options['id'] = $this->getId();
73 | }
74 | $this->registerAssets();
75 | Html::addCssClass($this->options, 'kv-alert ' . $this->type);
76 | }
77 |
78 | /**
79 | * Register the client assets for the [[Alert]] widget.
80 | */
81 | protected function registerAssets()
82 | {
83 | /**
84 | * @var View $view
85 | */
86 | $view = $this->getView();
87 | AlertAsset::register($view);
88 |
89 | if (!empty($this->delay) && $this->delay > 0) {
90 | $js = 'jQuery("#' . $this->options['id'] . '").fadeTo(' . $this->delay . ', 0.00, function() {
91 | $(this).slideUp("slow", function() {
92 | $(this).remove();
93 | });
94 | });';
95 | $view->registerJs($js);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/AlertTrait.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 1.0
17 | */
18 | trait AlertTrait
19 | {
20 | /**
21 | * @var string the type of the alert to be displayed. One of the `TYPE_` constants.
22 | */
23 | public $type;
24 |
25 | /**
26 | * @var string the icon type. Can be either 'class' or 'image'. Defaults to 'class'.
27 | */
28 | public $iconType;
29 |
30 | /**
31 | * @var string the class name for the icon to be displayed. If set to empty or null, will not be displayed.
32 | */
33 | public $icon;
34 |
35 | /**
36 | * @var array the HTML attributes for the icon.
37 | */
38 | public $iconOptions;
39 |
40 | /**
41 | * @var string the title for the alert. If set to empty or null, will not be displayed.
42 | */
43 | public $title;
44 |
45 | /**
46 | * @var array the HTML attributes for the title. The following options are additionally recognized:
47 | *
48 | * - `tag`: _string_, the HTML tag to render the title. Defaults to `span`.
49 | */
50 | public $titleOptions;
51 |
52 | /**
53 | * @var boolean show the title separator. Only applicable if [[title]] is set.
54 | */
55 | public $showSeparator;
56 |
57 | /**
58 | * @var integer the delay in microseconds after which the alert will be displayed. Will be useful when multiple
59 | * alerts are to be shown.
60 | */
61 | public $delay;
62 | }
63 |
--------------------------------------------------------------------------------
/src/Bs3Alert.php:
--------------------------------------------------------------------------------
1 |
19 | * @since 1.0
20 | */
21 | class Bs3Alert extends Alert implements AlertInterface
22 | {
23 | use AlertMethodsTrait;
24 | }
25 |
--------------------------------------------------------------------------------
/src/Bs4Alert.php:
--------------------------------------------------------------------------------
1 |
19 | * @since 1.0
20 | */
21 | class Bs4Alert extends Alert implements AlertInterface
22 | {
23 | use AlertMethodsTrait;
24 | }
25 |
--------------------------------------------------------------------------------
/src/Bs5Alert.php:
--------------------------------------------------------------------------------
1 |
19 | * @since 1.0
20 | */
21 | class Bs5Alert extends Alert implements AlertInterface
22 | {
23 | use AlertMethodsTrait;
24 | }
25 |
--------------------------------------------------------------------------------
/src/assets/css/alert.css:
--------------------------------------------------------------------------------
1 | /*!
2 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021
3 | * @package yii2-widgets
4 | * @version 1.1.5
5 | *
6 | * Styling for \kartik\widgets\Alert widget for Bootstrap 3.x
7 | */
8 | .bg-primary .alert-link {
9 | color: #fff !important;
10 | }
11 |
12 | .kv-alert {
13 | -webkit-transition: all 0.5s ease-in-out;
14 | -moz-transition: all 0.5s ease-in-out;
15 | -o-transition: all 0.5s ease-in-out;
16 | -ms-transition: all 0.5s ease-in-out;
17 | transition: all 0.5s ease-in-out;
18 | }
19 |
20 | .kv-alert-title {
21 | font-weight: bold;
22 | font-size: 18px;
23 | }
24 |
25 | .kv-alert-separator {
26 | clear: both;
27 | margin-top: 10px;
28 | margin-bottom: 13px;
29 | border: 0;
30 | height: 1px;
31 | background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0));
32 | background-image: -moz-linear-gradient(left, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0));
33 | background-image: -ms-linear-gradient(left, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0));
34 | background-image: -o-linear-gradient(left, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0));
35 | }
--------------------------------------------------------------------------------
/src/assets/css/alert.min.css:
--------------------------------------------------------------------------------
1 | /*!
2 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021
3 | * @package yii2-widgets
4 | * @version 1.1.5
5 | *
6 | * Styling for \kartik\widgets\Alert widget for Bootstrap 3.x
7 | */.bg-primary .alert-link{color:#fff!important}.kv-alert{-webkit-transition:all .5s ease-in-out;-moz-transition:all .5s ease-in-out;-o-transition:all .5s ease-in-out;-ms-transition:all .5s ease-in-out;transition:all .5s ease-in-out}.kv-alert-title{font-weight:700;font-size:18px}.kv-alert-separator{clear:both;margin-top:10px;margin-bottom:13px;border:0;height:1px;background-image:-webkit-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,.15),rgba(0,0,0,0));background-image:-moz-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,.15),rgba(0,0,0,0));background-image:-ms-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,.15),rgba(0,0,0,0));background-image:-o-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,.15),rgba(0,0,0,0))}
--------------------------------------------------------------------------------