Score:0

Paragraphs field preprocess hook not called

jp flag

To simplify this issue, I just have 2 hooks:

1. customtheme_preprocess_paragraph__registration_button()
2. customtheme_preprocess_paragraph__registration_button__default()

When I access a node with a registration button with a default view mode, only the first hook is called. Also, when I access the $variables['view_mode'] in that hook, it gives the value 'default'.

Furthermore, it only takes the paragraph--registration-button.html.twig as template, but not paragraph--registration-button--default.html.twig

I am using Drupal Core 9.5.4 and Paragraphs 1.15.0. Could this be something in my setup?

ru flag
`default` view mode is used as placeholder value for empty, unset... It seems very weird to overwrite the default template with another default template.
Ivan Ginovski avatar
jp flag
This happened for every view mode, no matter the name. For example, the sidebar view mode did not trigger the customtheme_preprocess_paragraph__registration_button__sidebar() hook, nor did it show the paragraph--registration-button--sidebar.html.twig template. Instead it is using the basic hook without any view modes and the basic template, as written in the description above.
Jaypan avatar
de flag
If I recall correctly, that's a bug in Paragraphs. It was a few years ago at least.
ru flag
Does this hook exist at all? I know of `hook_preprocess_paragraph__BUNDLE()`, but I've never used a `hook_preprocess_paragraph__VIEWMODE()`
mn flag
Just to be totally sure, you've cleared caches?
mn flag
I tested this out and found I could implement hook_preprocess_HOOK() for the default view mode of a paragraph and it is called. When you turn on Twig debugging and look at the "FILE NAME SUGGESTIONS" in HTML comments, do you see paragraph--registration-button--default.html.twig? I do.
Ivan Ginovski avatar
jp flag
Yes, indeed, I do see the twig suggestion in twig debug, but I do not know what happened after I updated PHP 7.4 --> PHP 8.1 and Drupal Core 9.3 --> 9.5, as well as Paragraphs module 1.12.0 --> 1.15.0. Now the view mode hooks are not triggered for any paragraph, as well as the templates are not displayed.
Ivan Ginovski avatar
jp flag
Found the issue, it was a custom patch that was changing the order of the template suggestions in function paragraphs_theme. Closing this because it is not needed.
Score:0
jp flag

This can be closed, it was a custom setup.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.