Retrieving settings for MT::Plugin
The Movable Type documentation does not really explain this well in its example. I've only gotten this far into getting/setting MT::PluginSettings objects because that's all that I've had to do so far, but this is a start to explain how to get it done right. I ran into a problem where the default scope setting of "blog" for the get_config_value method of MT::Plugin was not retrieving the value for the plugin-in for a particular blog, relying instead on the default value of 0. In the getter code, I did the following:
sub editBlogPolicies
{
my $plugin = shift;
my $app = shift;
my $template = $plugin->load_tmpl("blog_policy_editor.tmpl");
my $obj_type = $app->param('obj_type');
my $obj_id = $app->param('obj_id');
my $blog_id = $app->param('blog_id');
my $iter;
MT->log({message => $plugin->get_config_value("include_entries", "blog:1")});
if ($plugin->get_config_value("include_entries", "blog:$blog_id") == 1)
The MT::PluginSettings was built up like this:
my $plugin = MT::Plugin::BlogPolicy->new({
id => 'blogpolicy',
key => 'mt-blogpolicy',
name => 'Blog Policy Link Plug-in',
description => 'A plugin for organizing links to site policies.',
version => $VERSION,
author_name => 'Moi, non vouz',
schema_version => $SCHEMA_VERSION,
blog_config_template => 'config.tmpl',
settings => new MT::PluginSettings([
['include_entries', {Default=>0, Scope=>'blog'}]
])
});
The config.tmpl file looks like this:
<mtapp:setting
id="include_entries_setting"
label="Choose from entries and pages"
hint="<__trans phrase="By default, the plug-in only allows you to choose pages.">"
show_hint="1">
<input type="checkbox" name="include_entries" value="1"
id="include_entries" <mt:if name="include_entries">checked="true"</mt:if>/>
</mtapp:setting>
The key is to make sure that you use the form blog:$idnumber to get the correct setting, as shown in bold above.
I know the examples may seem a bit gratuitous, but most of my coding done at work is in Java, which makes me pine for good, detailed, example-rich documentation. Better to provide too little example, than too little, in my opinion.
