- Redmine Plugin Extension and Development
- Alex Bevilacqua
- 146字
- 2021-07-16 12:20:25
Model hooks
These hooks are used even less frequently than controller hooks but are being included here for completeness.
Model extension is better handled through the use of new methods or encapsulation of existing methods by means of the alias_method_chain
pattern. For a summary of alias_method_chain
see http://stackoverflow.com/a/3697391.
A common use-case for model hooks is the :model_project_copy_before_save
hook as this can be used to replicate content from our plugin that belonged to a specific project if that project is copied:
module RedmineKnowledgebase class Hooks < Redmine::Hook::ViewListener def model_project_copy_before_save(context = {}) source = context[:source_project] destination = context[:destination_project] if source.module_enabled?(:redmine_knowledgebase) # TODO: clone all categories # TODO: clone all articles # TODO: ensure cloned articles refer to cloned categories end end end end
The actual implementation has been left out in the preceding snippet, but placeholders have been left intact to illustrate what actions we could be taking.
推薦閱讀
- 零基礎學Visual C++第3版
- Visual C++程序設計學習筆記
- LabVIEW程序設計基礎與應用
- Visual FoxPro程序設計教程(第3版)
- Building a Home Security System with Raspberry Pi
- JavaScript Unlocked
- YARN Essentials
- Learning Apache Kafka(Second Edition)
- Mastering macOS Programming
- 3D少兒游戲編程(原書第2版)
- 精通Linux(第2版)
- 編程與類型系統
- Kotlin開發教程(全2冊)
- 汽車人機交互界面整合設計
- Learning iOS Security