Missing Documentation: Model Service - $_hook_id
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 35/100
- Issue 類型
- 文件
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- php
研究方向
Start with the “Building your own Models” guide named in the issue, then check the linked Model and Member source files to confirm how $_hook_id is used. Document the property and the hook naming behavior described in the issue; done means the guide explains which models expose extension hooks and how their event names are formed.
由索引模型根據 Issue 內容生成。
描述
Suggested Change
The Model Service documentation is missing a description of the $_hook_id property. The example I have found that uses this property is within the Member Model.
Reasoning
I was developing an add-on that contains a Contact model which belongsTo the ee:Member model.
Being curious in the process in which member models are saved/updated/inserted/deleted, I went searching for the extension hook call before_member_save($member, $values).
Based on the documentation, I was lead to believe that all extension hooks are invoked via some code that looks like:
if (ee()->extensions->active_hook('some_hook_method') === TRUE)
{
$str = ee()->extensions->call('some_hook_method', $hook_args...);
}
Unable to locate the existence of such code, with the hook method before_member_save, I did some deeper digging.
I learned that Models, which extend the ExpressionEngine\Service\Model class invoke the forwardEventToHooks($event) method. Walking through the code of this method, I discovered that:
- Models which have a
$_hook_idproperty defined are exposed to extension hook calls (Event name, either 'insert', 'update', 'save', or 'delete') based on the following convention:
$forwarded = array(
'before' . $uc_first_event => 'before_' . $hook_basename . '_' . $event,
'after' . $uc_first_event => 'after_' . $hook_basename . '_' . $event
);
- Internal events on the Model are also emitted without having to call them externally: For example:
$model = ee('Model')->get('Member')->first();
$model->validate(); // internally, $this->emit('beforeValidate') and $this->emit('afterValidate') are called
$model->save(); // internally, $this->emit('beforeSave') and $this->emit('afterSave') are called
// .... etc
Before I was attaching my own events for these actions and having to emit (invoke) them manually.
Additional context
I would recommend adding this documentation here: Building your own Models
- 主要語言
- CSS
- 星號
- 22
- 分支
- 79
- 平均合併
- 2 天 1 小時
- 30 天內合併 PR
- 6
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ExpressionEngine/ExpressionEngine-User-Guide 的其他 Issue
-
難度 1/5 1 小時以內 新手友好度 72/100
-
難度 1/5 1 小時以內 新手友好度 55/100
-
難度 2/5 1-3 小時 新手友好度 45/100
-
難度 1/5 1 小時以內 新手友好度 55/100
-
難度 2/5 1-3 小時 新手友好度 46/100
查看 ExpressionEngine/ExpressionEngine-User-Guide 的全部 Issue
相似的 Issue
-
hermes-queue
難度 1/5 1 小時以內 新手友好度 85/100
chrisalunlloyd2-sudo/mindpalace#337 ·
維護者通常 1 天內回覆
-
sync-en
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 1/5 1-3 小時 新手友好度 87/100
OWASP/CheatSheetSeries#2905 ·
維護者通常 1 天內回覆
-
Cleanup Setup可能已有人在做 @AlexanderKaran 今天認領。 未關閉documentation enhancement
難度 2/5 1-3 小時 新手友好度 64/100
e18e/framework-tracker#769 ·
維護者通常 1 天內回覆
-
bug v2
難度 1/5 1 小時以內 新手友好度 88/100
modelcontextprotocol/servers#5483 ·
維護者通常 1 天內回覆