From Mahara Wiki

Revision as of 17:44, 23 February 2020 by Mits (talk | contribs) (なぜ /local なのですか? Why /local?)

作成中です - mits (talk)

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

なぜ /local なのですか?




/local で何ができますか? What /local can do

過去において、/local 内の新しいフックは常にドキュメントが十分に整っているわけではなかったことに留意してください。そのため、最新情報を取得するための最善の方法はコードを調査することです。Note that in the past, new hooks in /local have not always been well documented. So when in doubt, your best bet for the latest information will be to search the codebase.

Also note that many of the files you can place under /local are already present in Mahara core. So you do have to "edit core" in order to edit them. However, these files will always be designed in such a way that you can safely and easily overwrite them with your own files during the upgrade process.

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

The file local/install.php contains functions named localpreinst() and localpostinst(). These are called during the Mahara installation process; localpreinst() is called early during the installation process, and localpostinst() is called as the final step in the installation process.

These methods are defined empty. You may override them to add your own code to the preinstall and postinstall process.

DBフック DB hooks

The /local directory has its own "version.php", "install.xml", and "upgrade.php" files. These act similarly to how they would for a standard Mahara plugin. When Mahara is first being installed, any database structures defined in local/install.xml will be created, and the version number in local/version.php will be stored in the database (as the config value "localversion"). If the version in local/version.php is incremented, Mahara will detect this and prompt the admin to run the upgrade script, running any appropriate upgrade sections in local/upgrade.php.

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

You can override language strings by placing lang files under /local/lang. This is particularly useful if you only need to change one or two language strings.

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

ヘルプをカスタムヘルプファイルでオーバーライドする 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.