I have a custom module in which I am trying to override a comment field's template in Drupal 9.3.
In my module file I have defined the hook_theme to override the core template in use. (comment.html.twig), which works, but it is not triggering the comment_preprocess_field hook in comment.module which then assigns the comment variables to the template.
My module file hook_theme is:
function MODULE_theme() {
return [
'field__field_FIELD_NAME' => [
'base_hook' => 'field',
]
];
}
This works and my custom template is displayed, but it is missing the comments variables passed from comment_preprocess_field.
If I place the template in my theme, the comment_preprocess_field hook runs and the variables are added to the template, but not when done from a custom module.
Does anyone know how to get the hook comment_preprocess_field to run when overriding a comment field template in a module?