How To Change Successful Flash Message In Rainlab Blog Plugin While Creating A Post?
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?
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');
});
});
}
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?