loveorigami / yii2-notification-wrapper

Yii2-notification-wrapper module renders a message from session flash (with ajax, pjax support and etc.) through Growl, Noty, Toastr and more libraries
MIT License
77 stars 20 forks source link

Unable to set custom title in a notification #7

Closed keeprock closed 8 years ago

keeprock commented 8 years ago

First of all. THANK YOU FOR YOUR MODULE. Its such a pain to get notification working inside Yii2, that I'd a breath of relief after I've seen your plugin actually works.

Start using your module and found an issue - there is no way to change a title of notification. Maybe that comes by design, but for me its a critical feature to have. Take a look at this code in Wrapper.php

  protected function getFlashes($layer)
    {
        $session = \Yii::$app->session;
        $flashes = $session->getAllFlashes();
        $options = $this->options;
        $result = [];

        foreach ($flashes as $type => $data) {
            $data = (array)$data;
            $type = (in_array($type, $this->types)) ? $type : self::TYPE_INFO;

            foreach ($data as $i => $message) {
                $result[] = $layer->getNotification($type, $message, $options);
            }

            $session->removeFlash($type);
        }

        if ($this->isAjax) {
            return Html::tag('script', implode("\n", $result));
        }

        return $this->view->registerJs(implode("\n", $result));
    }

Especially this line $type = (in_array($type, $this->types)) ? $type : self::TYPE_INFO;

Only option is either having a prescribed title or a title TYPE_INFO. There is no way to set it.

I created a fork of this. You may take a look at it, I will point a few differences here after I've completed everything.

keeprock commented 8 years ago

https://github.com/keeprock/yii2-notification-wrapper/commit/e2018896998de2a9569bb31aec74f991b160b152

keeprock commented 8 years ago

I did not test it against other layers, only Growl.

loveorigami commented 8 years ago

Hi, @keeprock It may be better to do so

$data['title'] = $options['useTitle'] ? $this->getTitle($type) : ''; // not worked now!
\Yii::$app->getSession()->setFlash('success',   ' <b>MY CUSTOM Title</b><br>noty success');

screenshot 2016-06-23 001

What you think about it?

loveorigami commented 8 years ago

@keeprock , I am added customTitleDelimiter for messages. See readme