Ad

How To Change Successful Flash Message In Rainlab Blog Plugin While Creating A Post?

- 1 answer

I am using October CMS and Rainlab Blog Plugin on my site. Whenever I create a post in Blog section in the backend, I see a flash message that says "Blog post created." As it appears right after I create a post, I need to know where I can find the method that runs this flash message. Searches in plugin folder didn't give any results,maybe I am missing something?

Ad

Answer

It's Defined inside the FormController Behaviour and it's based on the Model Name and the action that was performed, you can override this on the apropiated afterX method just in your model.

public function afterSave()
{
    Flash::purge();//clean the default messages
    Flash::success('Your custom message');
}

Remember to import the Flash Facade at the top of your file.

use Flash;

Also i suggest to use a language file to keep it clean

public function afterSave()
{
    Flash::purge();
    Flash::success('namespace.plugin.lang.code');
}

If you don't want to touch any Rainlab Blog files you can do it from another of your plugins binding listening the desired event on the boot event in your Plugin.php definition

public function boot()
{
    RainLabModelPost::extend(function ($model) {
        $model->bindEventOnce('model.afterSave', function () use ($model) {
            Flash::purge();
            Flash::success('namespace.plugin.lang.code');
        });
    });
}
Ad
source: stackoverflow.com
Ad