Home > How to combine MT::Plugin subclasses with config.yaml files

How to combine MT::Plugin subclasses with config.yaml files

December 22, 2009 Mike 0 comments
When I was working on refactoring part of the FacebookCommenters plugin to use a config.yaml file, I had to account for the save_config method that the plugin's pl file implemented. Movable Type plugins that are based on PL (Perl) files subclass MT::Plugin and accordingly can override methods in MT::Plugin like save_config. Getting around that is actually really this simple:

The perl module which implements the subclass:

package FacebookCommenters::Plugin;
use strict;
use base qw(MT::Plugin);

sub save_config
{
    my $plugin = shift;
   
    #Do stuff
   
    return $plugin->SUPER::save_config(@_);
}

1;
add this code (use 4 spaces, not tabs for indentation) to the config.yaml file:

init: >
    sub {
        my $plugin = shift;
        require FacebookCommenters::Plugin;
        bless $plugin, 'FacebookCommenters::Plugin';
    }
That's based on a trick that was explained on the Movable Type mailing list, but needed to be shared.

Categories: Tags: , , , ,