Fork me on GitHub
Please upgrade to 2.1.x here. The 2.0 branch is no longer being updated.
You should grab 2.1.9, released 18 March. It's what all the cool kids are doing.

[Documentation] Can I override a plugin's view in a custom theme?

I'm working on a theme, and I'd like to change the functionality of the Tagging plugin. Namely, I'd like to override class.tagmodule.php in my theme.

I know I can override the views in my theme, but what is the practice for overriding plugin modules like this?

Best Answers

  • mcu_hqmcu_hq yippie ki-yay ✭✭✭
    Answer ✓

    ZacharyLewis said:
    Do themes not allow that functionality?

    I don't think they do.

  • x00x00 MVP
    Answer ✓

    I provide this functionality on some of my plugins, especial where I am already overriding core views.

    It is not a standard thing though, But I support it in principle, as it is consistent with application views

    The principle of it is like so

        $PluginFolder = basename(dirname(__FILE__));
        $ThemeFolder = strtolower($PluginFolder);
        $Sender->ControllerName='';
        $Sender->ControllerFolder='';
        $ThemeViewLoc = CombinePaths(array(
            PATH_THEMES, $Sender->Theme,'views', $ThemeFolder
        ));
        if(file_exists($ThemeViewLoc.DS.strtolower($Sender->RequestMethod).'.php')){
            $Sender->ApplicationFolder= '';
            $Sender->ControllerName=$ThemeFolder;
        }else{
            $Sender->ApplicationFolder='plugins/'.$PluginFolder;
        }
    

    I use lower case folders within themes views folder as this is consistent with the current style

    grep is your friend.

    UnderDog

Answers

  • mcu_hqmcu_hq yippie ki-yay ✭✭✭
    edited April 2012

    You can try extending the specific class and then rewriting whatever function you want to override in the parent class. This is one of the reasons why my theme comes with a plugin.

  • How do I structure my folders to extend a plugin? Do I need a modules folder, or should I be putting this somewhere else?

  • hbfhbf wiki guy? MVP

    You nees to replicate the original structure.. copy the original file and folders you want to override into the theme.

  • I'm just not getting it. :(

    In my custom theme, I want to override TagModule::ToString(). It exists in vanilla-root/plugins/Tagging/class.tagmodule.php. Can I override this in my theme's folder, allowing me to distribute a theme with custom functionality? If so, how should my folder structure be set up?

    I've tried putting this file in the following locations, to no avail:

    • vanilla-root/themes/my-theme/class.tagmodule.php
    • vanilla-root/themes/my-theme/modules/class.tagmodule.php
    • vanilla-root/themes/my-theme/plugins/Tagging/class.tagmodule.php
  • mcu_hqmcu_hq yippie ki-yay ✭✭✭
    edited April 2012

    There may be better methods, but this is what I do:

    If you know where this function is called from (probably from a Fired Event), you can temporary buffer the output and the grab the results and filter them to your liking. In your case, I would look for the contents of TagModule::Tostring() such as a div with a specific class/ID and then replace it with whatever you want. The DOM document is perfect for this.

    Here is an example of what I do to make all of the meta elements fit into an unordered list. I pulled this code snippet of the traditional plugin views/discussion/helper_functions/ line 76:

                           ob_start();
                            $Sender->FireEvent('CommentInfo');
                            $CommentInfo = ob_get_contents();
                            ob_end_clean();
    
                            $doc = new DOMDocument("1.0", "utf-8");
                            $doc->loadHTML($CommentInfo);
                            $elements = $doc->getElementsByTagName('span');
                            $i = 0;
                            echo '<ul>';
                            foreach ($elements as $param) {
                                $node = $elements->item($i);
                                $text = $doc->saveHTML($node);
                                echo '<li>' . $text . '</li>';
                                $i++;
                            }
                            echo '</ul>';`
    
  • @mcu_hq Hmm... this seems a bit dirty. I was hoping to just be able to have my theme dictate the module to load, like it does with views.

    Do themes not allow that functionality?

  • mcu_hqmcu_hq yippie ki-yay ✭✭✭
    Answer ✓

    ZacharyLewis said:
    Do themes not allow that functionality?

    I don't think they do.

  • mcu_hq said:

    ZacharyLewis said:
    Do themes not allow that functionality?

    I don't think they do.

    Unfortunate. :(

  • x00x00 MVP
    Answer ✓

    I provide this functionality on some of my plugins, especial where I am already overriding core views.

    It is not a standard thing though, But I support it in principle, as it is consistent with application views

    The principle of it is like so

        $PluginFolder = basename(dirname(__FILE__));
        $ThemeFolder = strtolower($PluginFolder);
        $Sender->ControllerName='';
        $Sender->ControllerFolder='';
        $ThemeViewLoc = CombinePaths(array(
            PATH_THEMES, $Sender->Theme,'views', $ThemeFolder
        ));
        if(file_exists($ThemeViewLoc.DS.strtolower($Sender->RequestMethod).'.php')){
            $Sender->ApplicationFolder= '';
            $Sender->ControllerName=$ThemeFolder;
        }else{
            $Sender->ApplicationFolder='plugins/'.$PluginFolder;
        }
    

    I use lower case folders within themes views folder as this is consistent with the current style

    grep is your friend.

    UnderDog
  • x00x00 MVP
    edited April 2012

    no it goes the Base_Render_Before hook or a Create hook. basically any controller hook just before render.

    So the view is goign to be name of the request method lowercase.

    grep is your friend.

Sign In or Register to comment.