Actions

Difference between revisions of "開発者エリア/ローカルカスタマイゼーション"

From Mahara Wiki

Line 31: Line 31:
  
 
See [[Developer_Area/Language_strings#Custom_lang_strings_in_.2Flocal]] for details.
 
See [[Developer_Area/Language_strings#Custom_lang_strings_in_.2Flocal]] for details.
詳細は[[開発者エリア/言語ストリング#/local のカスタム言語ストリン]]をご覧ください。
+
詳細は[[開発者エリア/言語ストリング#/local のカスタム言語ストリング]]をご覧ください。
  
 
==== ヘルプをカスタムヘルプファイルでオーバーライドする Override help Custom help files ====
 
==== ヘルプをカスタムヘルプファイルでオーバーライドする Override help Custom help files ====

Revision as of 13:00, 14 April 2020

作成中です - mits (talk)

Maharaには /local ディレクトリが含まれます。これはコアコードを編集せずにMaharaサイトの動作を変更できるようにするための複数タイプのローカルカスタマイゼーション用フックを提供するための中心的な場所です。

なぜ /local なのですか?

あなたが新しいウェブサイト管理者の場合、「本当に必要ですか?」と自問することでしょう。私のMaharaサイトをカスタマイズしたい場合、Maharaコードを直接編集してはいかがでしょう?

その答えは「Maharaのコアコードを修正した場合、アップデートが困難になってしまいます」です。Maharaプロジェクトは定期的に更新をリリースしますが、極めて広範囲にわたる場合もあります。あなたのMaharaコードを全くカスタマイズしていない場合、単に既存のコードを更新済みコードに置換できます。しかし、あなたがMaharaコアファイルをカスタマイズしている場合、そして、私たちがそのファイルを更新している場合、あなたの更新を失ってしまうか、新しいバージョンのファイルの適用方法を見つけ出さなければなりません。特にGitのような適切なバージョンコントロールを使用することにより、この処理をさらに簡単にできます。しかし、Maharaコアコードの修正を最小限にする方が簡単です。

「/local」ディレクトリはMaharaをカスタマイズするための方法の1つです。プラグインおよびテーマはカスタマイズのための他の主要な方法です。オプションに関する完全なリストはカスタマイズをご覧ください。「/local」ディレクトリはMaharaをカスタマイズするための1つの方法にしかすぎません。プラグインおよびテーマがMaharaをカスタマイズするための主な手段です。オプションの完全なリストに関してカスタマイジングをご覧ください。

/local では何ができますか?

過去において、/local 内の新しいフックは常にドキュメントが十分に整っているわけではなかったことに留意してください。そのため、あなたにとって最新情報を取得するための最善の方法はコードを調査することです。

また、あなたがファイルをアップロードできる /local にはすでに多くのファイルが配置されていることにも留意してください。そのため、あなたがそれらのファイルを編集するには「コアを編集」しなければなりません。しかし、これらのファイルはアップグレード処理中に常にあなた独自のファイルで安全に簡単に上書きできるよう設計されています。

フックをインストールする

ファイル local/install.php には localpreinst() および localpostinst() という名称の関数が含まれます。これらはMaharaのインストール処理中に呼び出されます; localpreinst() はインストール処理の初期段階で呼び出されます。そして、localpostinst() はインストール処理の最終段階で呼び出されます。

これらのメソッドはは空のまま定義されています。あなたの独自コードを追加するため、事前インストールおよび事後インストール処理として空のメソッドにオーバーライドできます。

DBフック

/localディレクトリには独自の「version.php」「insatall.xml」および「upgrade.php」ファイルがあります。これらのファイルは標準のMaharaプラグインに対するのと同じように動作します。Maharaの初回インストール時、データベース構造の定義されたlocal/install.xmlが作成されます。また、local/version.phpのバージョンナンバーが (設定値「localversion」として) データベースに保存されます。local/version.phpのバージョンが増加した場合、Maharaはこれを検知してlocal/upgrade.phpの適切なアップグレードセクションを実行するためのアップグレードスクリプトを実行するよう管理者に促します。

カスタム言語ストリング Custom language strings

あなたは /local/lang 配下に言語ファイルを配置して言語ストリングをオーバーライドできます。

See Developer_Area/Language_strings#Custom_lang_strings_in_.2Flocal for details. 詳細は開発者エリア/言語ストリング#/local のカスタム言語ストリングをご覧ください。

ヘルプをカスタムヘルプファイルでオーバーライドする Override help Custom help files

You can override the content of help filesHelp files can be customized by placing help files under /local/lang.

See Developer_Area/Language_strings#Custom_help_files_in_.2Flocal for details.

カスタムテーマオーバーライド Custom theme overrides

You can provide custom theme templates under /local/theme/templates, as if this were the "templates" directory of a theme. Likewise, you can customize static assets like images by placing them under /local/theme/static. See Customising/Themes/1.10#Local_theme_overrides

Prior to Mahara 1.10, template files placed in /local in this way were placed in order of precedence below the current theme, but above any parent themes. This made them mostly useful for supporting the creation of new pages, rather than overriding existing pages. Also prior to Mahara 1.10, the template files of plugins, even those that ship with Mahara, cannot be customized via the /local directory. As of Mahara 1.10 these restrictions have been lifted; /local theme contents come first in precedence, and /local can include theme contents for plugins.

/local/lib.php の様々なフック関数 Miscellaneous hook functions in /local/lib.php

The Mahara code base contains a number of places where the presence of a local "hook" function is checked for, and if present, this function is executed. These are meant to provide an easy method for site administrators to change core functionality of Mahara without changing core code.

As of Mahara 1.10, all of these are documented in the header to the /local/lib.php file. Here are some of the highlights:

  • local_can_remove_viewtype($viewtype): Can be used to block users from being able to delete certain types of views
  • local_get_allowed_blocktypes($category, $view): Can be used to remove some blocktypes from the page builder.
  • local_get_allowed_blocktype_categories($view): Can be used to remove some blocktype categories from the page build.r
  • local_header_top_content(): Returned data is printed at the top of the "head" tag on most pages. (If you only need to print static content, as of Mahara 1.9 you can do this using the $cfg->additionalhtmlhead config option, described in lib/config-defaults.php)
  • local_main_nav_update(&$menu): Can be used to modify the contents of the main navigation menu
  • local_right_nav_update(&$menu): Can be used to modify the contents of the sidebar
  • local_register_submit(&$values): Pre-registration hook. Content added to $values['extra'] will be automatically stored in the database in usr_registration.extra
  • local_post_register($registration): Post-registration hook. Meant to be a place where data stored in usr_registration.extra can be retrieved and applied to the now-registered user.
  • local_init_user(): Hook function, called on each pageload immediately after the global $USER object is initiated.