Missing Documentation: Model Service - $_hook_id
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 35/100
- Type d'issue
- Documentation
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- php
- Domaine
- documentation
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- CSS
- Étoiles
- 22
- Forks
- 79
- Merge moyen
- 2 j 1 h
- PR mergées (30 j)
- 6
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de ExpressionEngine/ExpressionEngine-User-Guide
-
Inconsistent code block spacingOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
-
registration form docsOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 55/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 45/100
-
Clarify autosave interval valueOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 55/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 46/100
Toutes les issues de ExpressionEngine/ExpressionEngine-User-Guide
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Textualize/textual#6753 · 1 commentaire ·
-
area: core area: docs good first issue help wanted lane: free-agent priority: P3 roadmap size: XS type: task
Difficulté 1/5 Moins d'une heure Accessibilité débutants 86/100
arminazimi/seaworthy#701 ·
Les mainteneurs répondent en général sous 1 jour
-
Use registered media types for HDF5 and NetCDF, and stop claiming media_type must be IANA-registeredOuvertedocumentation metadata
Difficulté 2/5 1-3 heures Accessibilité débutants 87/100
Les mainteneurs répondent en général sous 1 jour
-
doc-qa/index.html: data: favicon is blocked by img-src 'none' (one CSP console error per load)Ouvertebug good first issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
elhajahmadj/offline-emergency-library#156 ·
Les mainteneurs répondent en général sous 1 jour
-
7.2 user documentation (HelpHub)
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
WordPress/Documentation-Issue-Tracker#2559 · 1 commentaire ·