Overwrite Blog Module Configuration


I'd like to change the default behaviour for comments. I'd like the option to leave comments turned on, but I'd like the comments to be turned off by default.

I can do this by changing the order of the yes/no in the following code, but I'd rather not do it right in the Blog module in case it's updated.

Please let me know your thoughts on the best way to accomplish this.

if (!isset($values['allow_comments']))<br /> {<br /> $fields['allow_comments']['value'] = ($CI->fuel->blog->config('allow_comments')) ? 'yes' : 'no';<br /> }


  • If I understand you correct, I believe that can be adjusted in the blog config which is by default located in the fuel/modules/blog/config/blog.php. If you don't have a copy of that file a fuel/application/config/blog.php, be sure to copy it over there (it will overwrite the default). Then for the following line, change it to false:

    $config['blog']['allow_comments'] = FALSE;
  • No, that allows comments but turns them on by default. I want comments allowed, but turned off by default.

    Thanks :)

  • If you set it to FALSE and create a new blog post, it should select no as default in the radio button under the Settings of the post (existing blog posts will retain what they were saved at). Is that not what you are seeing or am I misunderstanding?

  • It doesn't seem to work. I set it as FALSE and turned the Settings-> Blog -> Allow Comments as checked and it makes the radio select yes by default. If the checkbox is unchecked it hides the option completely.
    If there's nothing built-in, I can just swap the yes/no in the model. I was just thinking there was another way that I was missing.

  • edited December 2020

    Oh yep... sorry... I see what you are saying now. Yeah, line 128 in Blog_posts_model unsets that field. You could extend that model and overwrite the form_fields method using the module_overwrites:

    Rough Example (you can put this file in your fuel/application/models/ folder):

    My_blog_posts_model extends Blog_posts_model
        function form_fields($values = array(), $related = array())
                $fields = parent::form_fields($values);
                $fields['allow_comments'] = array('type' => 'enum', 'options' => array('yes', 'no'), 'value' => ($CI->fuel->blog->config('allow_comments') ? 'yes' : 'no') )
                return $fields;
  • That sounds like the optimal solution, but I'm having a hard time getting the system to see My_blog_posts_model.php in /fuel/applications/models/

    I've searched for the proper technique to overwrite the Blog module specifically, but no luck.

    Here's what I have, but it's not working:
    $config['module_overwrites']['blog']['blog_posts_model'] = 'My_blog_posts_model';
    In MY_fuel_modules.php

    Thanks again :)

  • I think you just want the following:

    $config['module_overwrites']['blog_posts']['model_name'] = 'My_blog_posts_model';
  • edited December 2020

    Yes! That worked.

    Thank you. I kept putting the module_name into the module_name spot instead of thinking it was the key 🤦‍♂️

    I adjusted the code to be even simpler since all I want is the default value to be no.
    class My_blog_posts_model extends Blog_posts_model<br /> {<br /> function form_fields($values = array(), $related = array())<br /> {<br /> $fields = parent::form_fields($values);<br /> $CI =&amp; get_instance();<br /> $fields['allow_comments']['value'] = 'no';<br /> return $fields;<br /> }<br /> }

Sign In or Register to comment.