Ad

Non English Slug For October Cms Blog

- 1 answer

Using build 422 of October cms and Rainlab blog plugin, it's impossible to have a non English slug for blog post, every time it says "The slug format is invalid."

Is there any solution or workaround to resolve this limitation?

Ad

Answer

I would recommend you follow the extending guide of octobercms and extend it. That way you can safely update the Blog plugin without having to worry about re-editing it again, or when you have to reinstall octobercms having to remember to edit it.

use Rainlab\Blog\Models\Post;

class Plugin extends PluginBase 
{
    public function boot()
    { 
        // Extend post Model
        Post::extend(function($model) {
            // Only do stuff when validation is triggered
            $model->bindEvent('model.beforeValidate', function() use ($model) {
                 // Find the regex holding value to avoid hardcoding array index
                 foreach($model->rules as $key => $value) {
                     if(strpos($value, 'regex:') !== false) {
                          // unset validation rule containing the regex.
                          unset($model->rules[$kt validation rule containing the regex.
                          unset($model->rules[$key]);
                          break;
                     }
                 }
            }
        });
    }
}
Ad
source: stackoverflow.com
Ad