Missing Documentation: Model Service - $_hook_id
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Documentación
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- php
- Área
- documentation
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- CSS
- Estrellas
- 22
- Forks
- 79
- Merge medio
- 2 d 1 h
- PR fusionados (30 d)
- 6
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ExpressionEngine/ExpressionEngine-User-Guide
-
Inconsistent code block spacingAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
-
registration form docsAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 55/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
-
Clarify autosave interval valueAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 55/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 46/100
Todos los issues de ExpressionEngine/ExpressionEngine-User-Guide
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
obsidianmd/obsidian-developer-docs#281 ·
Los mantenedores suelen responder en 4 días
-
Area: PDF support
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
orbeon/orbeon-forms#8053 ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
JWhite212/SignalLadder#213 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
aws-samples/sample-per-model-bedrock#782 ·
Los mantenedores suelen responder en 1 día
-
docs(sync): document `sync.local_source` and how to recover entries written before v1.42.0Posiblemente ocupada @jdx la tomó hoy. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 86/100
Los mantenedores suelen responder en 1 día