21-5 フィールドの拡張とオブジェクトテーブルの追加

この節には追加情報があります:「17-2 検索対象のフィールドを変更する」「21-5 フィールドの拡張とテーブルの追加」の追加情報

419ページ

config.yaml

name: Example Plugin
id: Example
version: 1.0
schema_version: 1.0
object_types:
    entry:
        price:
            type: string
            size: 32
            label: Price

420ページ

config.yaml

callbacks:
    MT::App::CMS::template_param.edit_entry: $Example::Example::CMS::get_product_field

CMS.pm

package Example::CMS;
use strict;
sub get_product_field {
    my ($cb, $app, $param, $tmpl) = @_;
    my $field = $tmpl->getElementById('keywords');
    my $node = $tmpl->createElement('app:setting',
                             { id => 'price',
                               label => 'Price',
                               label_class => "top-label" });
    my $innerHTML = '<input type="text" name="price" id="price" class="full-width" value="<mt:GetVar name="price" />" />';
    $node->innerHTML($innerHTML);
    $tmpl->insertAfter($node, $field);
}
 
1;

422ページ

config.yaml

name: Example Plugin
id: Example
version: 1.0
schema_version: 1.0
object_types:
    product: Example::Product

Product.pm

package Example::Product;
use strict;
use base qw( MT::Object MT::Revisable );
 
__PACKAGE__->install_properties({
    column_defs => {
        'id' => 'integer not null auto_increment',
        'entry_id' => 'integer not null',
        'name' => {
            type => 'string',
            size => 255,
            label => 'Name',
            revisioned => 1
        },
        'price' => {
            type => 'string',
            size => 10,
            label => 'Price',
            revisioned => 1
        },
        'size' => {
            type => 'string',
            size => 5,
            label => 'Size',
            revisioned => 1
        },
    },
    indexes => {
        entry_id => 1,
        name => 1,
        price => 1,
    },
    child_of => 'MT::Entry',
    datasource => 'product',
    primary_key => 'id',
});
 
1;

このアーカイブについて

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。