LoginSignup
1
0

More than 5 years have passed since last update.

【MT】MTOSにAnotherCustomFieldsプラグインを導入

Posted at

MTOSにAnotherCustomFieldsプラグインを導入しました。(だいぶ昔だけど覚書があったので投稿)

AnotherCustomFieldsは、藤本氏が開発したプラグインです。

公式サイト にライセンスについての記載がありますので、ご一読ください。
また、プラグインの解説書もあるのようなので、詳しく知りたい方は購入してください。

ライセンス
AnotherCustomFieldsプラグインは、デュアルライセンスで配布します。

MTOSと組み合わせる場合はGPLv2に従い、MTOSにご自由にインストールしてお使いいただくことができます。
一方、商用ライセンスのMovable Typeと組み合わせる場合は、ライセンス料(インストール先1件につき5,000円)をお支払いください。

AnotherCustomFieldsプラグインの解説書(PDF)は、有償(9,800円)での販売とさせていただきます。
解説書やライセンスをご希望の方は、メールフォームよりお問い合わせください。

下記が導入した環境です。

環境 バージョン
MTOS 5.2.13
AnotherCustomFields 1.23

AnotherCustomFields」からプラグインをダウンロードします。
プラグインのフォルダ内にある plugins > AnotherCustomFields > config.yaml のファイルを開きます。
config.yamlをテキストエディタなどで開くと既に記述ありますが、記述は残したまま最後に下記のように追記することでカスタムフィールドを追加できます。
下記が追記するテンプレートです。

schema_version: 1.00
object_types:
  entry:
    カスタムフィールド名:
      type: string
      size: 255
      revisioned: 1
      acf:
        type: タイプ名
        label: ラベル名
        tag: タグ名

カスタムフィールドを複数追加したい場合は下記の記述のカスタムフィールド名からタグ名までの情報を最後にコピペして追加してください。
下記が2つのカスタムフィールドを追加する記述例になります。

schema_version: 1.00
object_types:
  entry:
    カスタムフィールド名:
      type: string
      size: 255
      revisioned: 1
      acf:
        type: text
        label: ラベル名
        tag: タグ名
    カスタムフィールド名:
      type: string
      size: 255
      revisioned: 1
      acf:
        type: text
        label: ラベル名
        tag: タグ名

注意

config.yamlファイルの最後に改行を入れないとエラーが表示される場合があります。
おそらくサーバーの環境によるもので、改行を入れなくてもエラーにならない場合もあります。
下記のようなエラーが表示されたときは、最後に改行を残しておくとエラーが表示されなくなります。

Got an error: Error reading /home/xxxx/config.yaml: Failed to load YAML document from string

schema_version

「schema_version: 1.00」を変更することで、データベース上にカスタムフィールドが追加されます。
そのため、カスタムフィールドを追加したときのバージョンの数字を「schema_version: 1.01」のように変更してアップロードしてください。
shcema_versionを変更すると、MTにアクセスしたときに「アップグレード開始」の画面が表示されます。
このときにデータベースにカラムが追加されます。
カスタムフィールドを追加してもschema_versionを変更せずにデータベース上にカスタムフィールド名のカラムがないとエラーが表示されます。
カスタムフィールドを追加したときは必ずschema_versionを変更してください。

phpMyAdminからデータベースの「mt_entry」を確認すると「entry_カスタムフィールド名」の名称でカラムが追加されています。
この追加されたカラムの文字コードを「utf8_general_ci」に変更してください。
おそらく最初の文字コードは「ujis_japanese_ci」になっているかと思います。
「ujis_japanese_ci」のままだと「~や①」などの文字を入力して保存すると「?」になってしまいます。
そのような文字を使う場合は、「utf8_general_ci」などに文字コードを変更してください。

カスタムフィールド名

データベースに追加されるカラム名になります。
カラム名として使用できる半角英数字で入力してください。
アンダーバーも使える?

タイプ名

タイプ名とは一行テキストなのか、複数行のテキストなのかなどカスタムフィールドのタイプを入力します。

一行テキストの場合は下記のように入力します。

     type: text

複数行テキストの場合は下記のように入力します。

     type: textarea

プラグインの作者のページには下記のようなタイプが追加可能と記載があります。
それぞれどのような記載するのかはわかりません。
詳細は、マニュアルを購入するなどして確認してください。

2-2.表示できるフィールドのタイプ

以下のようなタイプのフィールドを表示することができます。

1行テキスト入力
複数行テキスト入力
日本の郵便番号
日本の電話番号
チェックボックス
セレクト
ラジオボタン
画像
動画
音声
ファイル

ラベル名

ラベル名はMTの管理画面でカスタムフィールドの入力欄の上に表示される文字になります。
何の項目の入力なのかわかるように記述するのがよろしいかと思います。
日本語もOKです。

タグ名

有償になりますが、プラグインの制作者である藤本氏が解説書(PDF)を販売しております。
もっと詳しく知りたい方は、「AnotherCustomFields」から購入してください。

<mt:If tag="column00Text">
テキスト<mt:column00Text>
</mt:If>

<mt:Entries blog_ids="2">
<mt:If tag="HMText01"><mt:HMText01></mt:If>
</mt:Entries>

エラー表示されたときの対処

config.yamlをアップロードし、MTの管理画面にアクセスするとアップデートが開始されます。
アップデート中にエラーが表示されたときは、phpMyAdminなどでデータベースにアクセスしてください。

「mt_entry」内に追加したカスタムフィールドのカラムが追加されています。
データベースに書き込まれる前にエラーが表示されたときは、追加されていません。
追加されているときは、追加された途中のカラムを削除して、「config.yaml」を修正するなどして、再度MTの管理画面にアクセスしてアップデートを試みてください。

例えば、「text01」というカスタムフィールド名にconfig.yamlに記述していた場合は、データベースのカラムに「entry_text01」と追加されています。
記述したカスタムフィールド名の頭にentry_という文字が付与されてデータベースのカラムに登録されます。

サンプルコード(全文)

name: AnotherCustomFields
id: AnotherCustomFields
author_name: <__trans phrase="Hajime Fujimoto">
author_link: http://www.h-fj.com/blog/
description: <__trans phrase="This plugins adds another custom fields functionality.">
plugin_link: http://www.h-fj.com/blog/mt5plgdoc/anothercustomfields.php
doc_link: http://www.h-fj.com/blog/mt5plgdoc/anothercustomfields.php
l10n_class: AnotherCustomFields::L10N
version: 1.23
callbacks:
  init_app: $AnotherCustomFields::AnotherCustomFields::ContextHandlers::install_tags
  restore: $AnotherCustomFields::AnotherCustomFields::BackupRestore::restore
applications:
  cms:
    callbacks:
      template_param.edit_entry: $AnotherCustomFields::AnotherCustomFields::CMS::edit_entry
      template_param.edit_page: $AnotherCustomFields::AnotherCustomFields::CMS::edit_entry
      template_param.edit_category: $AnotherCustomFields::AnotherCustomFields::CMS::edit_category
      template_param.edit_folder: $AnotherCustomFields::AnotherCustomFields::CMS::edit_category
      template_param.edit_blog: $AnotherCustomFields::AnotherCustomFields::CMS::edit_blog
      template_param.edit_website: $AnotherCustomFields::AnotherCustomFields::CMS::edit_blog
      template_param.cfg_prefs: $AnotherCustomFields::AnotherCustomFields::CMS::cfg_prefs
      template_param.edit_author: $AnotherCustomFields::AnotherCustomFields::CMS::edit_author
#      template_param.edit_asset: $AnotherCustomFields::AnotherCustomFields::CMS::edit_asset_adm
      template_param.footer: $AnotherCustomFields::AnotherCustomFields::CMS::add_footer
      template_param.header: $AnotherCustomFields::AnotherCustomFields::CMS::add_header
      template_param.asset_insert: $AnotherCustomFields::AnotherCustomFields::CMS::asset_insert
      cms_pre_save.entry: $AnotherCustomFields::AnotherCustomFields::CMS::pre_save_entry
      cms_pre_save.page: $AnotherCustomFields::AnotherCustomFields::CMS::pre_save_entry
      cms_pre_save.category: $AnotherCustomFields::AnotherCustomFields::CMS::pre_save_category
      cms_pre_save.folder: $AnotherCustomFields::AnotherCustomFields::CMS::pre_save_category
      cms_pre_save.blog: $AnotherCustomFields::AnotherCustomFields::CMS::pre_save_blog
      cms_pre_save.website: $AnotherCustomFields::AnotherCustomFields::CMS::pre_save_blog
      cms_pre_save.author: $AnotherCustomFields::AnotherCustomFields::CMS::pre_save_author
#      cms_pre_save.asset: $AnotherCustomFields::AnotherCustomFields::CMS::pre_save_author
      cms_post_save.entry: $AnotherCustomFields::AnotherCustomFields::CMS::post_save_entry
      cms_post_save.page: $AnotherCustomFields::AnotherCustomFields::CMS::post_save_entry
      cms_post_save.category: $AnotherCustomFields::AnotherCustomFields::CMS::post_save_category
      cms_post_save.folder: $AnotherCustomFields::AnotherCustomFields::CMS::post_save_category
      cms_post_save.blog: $AnotherCustomFields::AnotherCustomFields::CMS::post_save_blog
      cms_post_save.website: $AnotherCustomFields::AnotherCustomFields::CMS::post_save_blog
      cms_post_save.author: $AnotherCustomFields::AnotherCustomFields::CMS::post_save_author
      cms_save_filter.entry: $AnotherCustomFields::AnotherCustomFields::CMS::save_filter
      cms_save_filter.page: $AnotherCustomFields::AnotherCustomFields::CMS::save_filter
      cms_save_filter.category: $AnotherCustomFields::AnotherCustomFields::CMS::save_filter
      cms_save_filter.folder: $AnotherCustomFields::AnotherCustomFields::CMS::save_filter
      cms_save_filter.blog: $AnotherCustomFields::AnotherCustomFields::CMS::save_filter
      cms_save_filter.author: $AnotherCustomFields::AnotherCustomFields::CMS::save_filter
      cms_save_filter.asset: $AnotherCustomFields::AnotherCustomFields::CMS::save_filter
      cms_pre_preview: $AnotherCustomFields::AnotherCustomFields::CMS::preview
acf_field_types: $AnotherCustomFields::AnotherCustomFields::CMS::load_acf_field_types
acf_field_classes:
  entry: 1
  category: 1
  blog: 1
  author: 1
#  asset: 1
acf_restore_classes:
  entry:
    - entry
    - page
  category:
    - category
    - folder
  blog:
    - blog
    - website
  author:
    - author
#  asset:
#    - asset
#    - file
#    - image
#    - video
#    - audio
tags:
  function:
    ACFOptionValue: $AnotherCustomFields::AnotherCustomFields::ContextHandlers::field_option_value
    ACFOptionLabel: $AnotherCustomFields::AnotherCustomFields::ContextHandlers::field_option_label
    ACFOptionCount: $AnotherCustomFields::AnotherCustomFields::ContextHandlers::field_option_count


schema_version: 1.02
object_types:
  entry:
    recruittext01:
      type: string
      size: 255
      revisioned: 1
      acf:
        type: textarea
        label: 募集職種
        tag: RecruitText01
    recruittext02:
      type: string
      size: 255
      revisioned: 1
      acf:
        type: textarea
        label: 雇用形態
        tag: RecruitText02
    recruittext03:
      type: string
      size: 255
      revisioned: 1
      acf:
        type: textarea
        label: 応募資格
        tag: RecruitText03

参考サイト

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0