Missing Documentation: Model Service - $_hook_id
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Dokumentation
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- php
- Bereich
- documentation
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- CSS
- Sterne
- 22
- Forks
- 79
- Ø Merge
- 2 T. 1 Std.
- Gemergte PRs (30 T.)
- 6
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ExpressionEngine/ExpressionEngine-User-Guide
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
-
registration form docsOffen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 55/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 45/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 55/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 46/100
Alle Issues in ExpressionEngine/ExpressionEngine-User-Guide
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
fsprojects/FSharp.Formatting#1370 ·
Maintainer antworten meist innerhalb von 1 Tag
-
hermes-queue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
chrisalunlloyd2-sudo/mindpalace#337 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
sync-en
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
sync-en
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag