「サブプラグイン」の版間の差分

提供:MoodleDocs
移動先:案内検索
編集の要約なし
編集の要約なし
36行目: 36行目:


それぞれの活動モジュールでは<tt>db/subplugins.php</tt>でサブプラグインのセット「タイプ」(サブプラグインそのものと混同しないでください) を定義できます。
それぞれの活動モジュールでは<tt>db/subplugins.php</tt>でサブプラグインのセット「タイプ」(サブプラグインそのものと混同しないでください) を定義できます。
このファイルには$subpluginsという配列が必要であり、プラグインタイプをキーとしてプラグインを含むディレクトリを指定してください。例えば<tt>mod/workshop/db/subplugins.php</tt>では次のようになります:
このファイルには$subpluginsという配列が必要であり、プラグインタイプをキーとしてプラグインを含むディレクトリを指定してください。例えば<tt>mod/workshop/db/subplugins.php</tt>では以下のようになります:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
$subplugins = array(
$subplugins = array(
95行目: 95行目:
== サブプラグインを書く Writing a sub-plugin ==
== サブプラグインを書く Writing a sub-plugin ==


A lot of the basic structure of a sub-plugin is the same as any other plugin. サブプラグインの基本的な構造の多くは他のプラグインと同じです。It can have a <tt>version.php</tt> (don't forget the object is '''$plugin''' not '''$mod'''), a <tt>lang</tt> directory, and can have a <tt>db</tt> directory with <tt>install.xml</tt> and all the others files can can go in there. <tt>version.php</tt>(オブジェクトは'''$mod'''ではなく'''$plugin'''であることを忘れないでください)、<tt>lang</tt>ディレクトリ、そして<tt>install.xml</tt>および他のすべてのファイルを含む<tt>db</tt>ディレクトリを持つことができます。
サブプラグインの基本的な構造の多くは他のプラグインと同じです。<tt>version.php</tt> (オブジェクトは'''$mod'''ではなく'''$plugin'''であることを忘れないでください)、<tt>lang</tt>ディレクトリ、そして<tt>install.xml</tt>および他のすべてのファイルを含む<tt>db</tt>ディレクトリを持つことができます。


As a minimum, you will need the version.php file and a language file with 'pluginname' defined.  
As a minimum, you will need the version.php file and a language file with 'pluginname' defined.  

2023年7月7日 (金) 15:06時点における版

作成中です - Mitsuhiro Yoshida (トーク)

サブプラグインタイプを定義する

Moodle 2.6


サブブラグインは以下のプラグインタイプでサポートされます:

  • 活動モジュール
  • HTMLエディタ (2.4以降)
  • ローカルプラグイン (2.6以降)
  • 管理ツール (2.6以降)

db/subplugins.json

テンプレート:Moodle 3.8

Moodle 3.8以降、サブプラグインはdb/subplugins.jsonファイルに定義する必要があります。例えばmod/workshop/db/subplugins.jsonでは次のようになります:

{
    "plugintypes": {
        "workshopform": "mod/workshop/form",
        "workshopallocation": "mod/workshop/allocation",
        "workshopeval": "mod/workshop/eval"
    }
}

複数のバージョンをサポートするプラグインがある場合、あなたはdb/subplugins.jsonファイルおよび以下の内容を含むdb/subplugins.phpバリアントを作成する必要があります:

<?php

$subplugins = (array) json_decode(file_get_contents(__DIR__ . "/subplugins.json"))->plugintypes;

db/subplugins.php

それぞれの活動モジュールではdb/subplugins.phpでサブプラグインのセット「タイプ」(サブプラグインそのものと混同しないでください) を定義できます。 このファイルには$subpluginsという配列が必要であり、プラグインタイプをキーとしてプラグインを含むディレクトリを指定してください。例えばmod/workshop/db/subplugins.phpでは以下のようになります:

$subplugins = array(
    'workshopform'       => 'mod/workshop/form',
    'workshopallocation' => 'mod/workshop/allocation',
    'workshopeval'       => 'mod/workshop/eval',
);

これは次の3つのプラグインタイプを定義しています: workshopform, workshopallocation, workshopeval プラグイン自体はそれぞれmod/workshop/form, mod/workshop/allocation, mod/workshop/evalに存在できます。 これらのディレクトリではサブディレクトリ内にいくつものプラグインを含めます。


言語ストリング

あなたはモジュールの言語文字列にサブプラグインを識別するためのエントリを追加する必要もあります。mod/workshop/lang/en/workshop.phpにあるワークショップモジュールを例にした場合、以下のようになります:

$string['subplugintype_workshopallocation'] = 'Submissions allocation method';
$string['subplugintype_workshopallocation_plural'] = 'Submissions allocation methods';
$string['subplugintype_workshopeval'] = 'Grading evaluation method';
$string['subplugintype_workshopeval_plural'] = 'Grading evaluation methods';
$string['subplugintype_workshopform'] = 'Grading strategy';
$string['subplugintype_workshopform_plural'] = 'Grading strategies';

命名規則および推奨事項

  1. サブプラグイン名には半角英字および記号 ([a-z]+) のみ使用してください
  2. サブプラグインタイプはグローバルに一意である必要があります - 他のプラグインタイプ、コアサブシステムまたは他のサブプラグインタイプと衝突しないようにしてください。
  3. データベースのテーブル名の長さには制限があるため、サブプラグインのタイプ名は短くしてください。

plugininfoクラス

Moodle 2.6


開発者は常にサブプラグインの属性を記述するpluginfoクラスを定義すべきです。

Moodle 2.5ではこのクラスはplugininfo_plugintypeという名称でplugindir/adminlib.phpファイルでの記述が求められました。

Moodle 2.6以降、クラスは\plugintype_pluginname\plugininfo\subtypenameと呼ばれます。また、plugindir/classes/plugininfo/subtypename.phpファイル内に記述する必要があります。

以下、mod_feedというプラグインおよびfeedviewというサブタイプのクラスの例です (簡潔にするためdocのコメントは省略しています):

namespace mod_feed\plugininfo;
class feedview extends \core\plugininfo\base {
}

アンインストールサポート

Moodle 2.6


Moodle 2.6以降、サブプラグインタイプではカスタムアンインストール方法を定義できます。あなたが個々のサブプラグインをアンインストールする際、いくつかのデータベーステーブルまたは設定をクリーンアップする必要がある場合、これは便利です。

管理ページ

Moodleにはインストール済みサブプラグインの基本的なリストおよびサブプラグインのアンインストールサポートのみ含まれます。

サブプラグインを書く Writing a sub-plugin

サブプラグインの基本的な構造の多くは他のプラグインと同じです。version.php (オブジェクトは$modではなく$pluginであることを忘れないでください)、langディレクトリ、そしてinstall.xmlおよび他のすべてのファイルを含むdbディレクトリを持つことができます。

As a minimum, you will need the version.php file and a language file with 'pluginname' defined. 最低限、あなたはversion.phpファイルおよび「pluginname」が定義された言語ファイルが必要です。

However the details of what APIs the sub-plugin has to provide depends on the type of sub-plugin it is. For example, and quiz report has to follow the rules for quiz reports that the quiz module sets, and a workshop allocation has to follow the rules set by the workshop module. When you create a new type of sub-plugin, you should document the expected API. しかし、サブプラグインが提供しなければならないAPIの詳細はサブプラグインのタイプに依存します。例えば小テストレポートは小テストモジュールが設定する小テストレポートのルールに従わなければならず、ワークショップの割り当てはワークショップモジュールが設定するルールに従わなければなりません。新しいタイプのサブプラグインを作成する場合、あなたは期待されるAPIを文書化する必要があります。

設定ページ Settings pages

A subplugin can include a settings.php page but it will not be included automatically. It is the responsibility of the parent module's settings.php file to include the subplugin's settings pages. See lib/editor/tinymce/ for a real example. サブプラグインはsettings.phpページをインクルードできますが、自動的にインクルードされることはありません。サブプラグインの設定ページをインクルードするのは親モジュールのsettings.phpファイルの責任です。実際の例はlib/editor/tinymce/をご覧ください。

サブプラグインの配布 Distribution of sub-plugins

Basic set of sub-plugins is usually distributed with each add-on. It is also possible to submit add-on sub-plugins separately.