I’m generating theme suggestions based on the formdazzle module, I made my own variant because I needed another level of granularity of theme names and it works fine.
Well, in the alter hook I have the key #pre_render and the method to generate de suggestions:
Example
$form['#formdazzle'] = ['form_id' => $form_id]; // Add our pre-render function to the end of the list. if (!isset($form['#pre_render'])) { $form['#pre_render'] = []; } $form['#pre_render'][] = [self::class, 'preRenderForm'];
When the form loads the suggestions work fine, now, I have a paragraph and the button to add more paragraph elements, when I click it Ajax is executed by default and the new element is created, but theme suggestions are not regenerated, and the new markup that is replaced is not the correct one(use drupal default suggestions). That is, I lose all the markup of the templates.
Doing tests, I notice that when the ajax event is executed, the pre_render function is not executed again and that is why the suggestions are not generated again.
Is there a way to make the pre_render rerun after an Ajax event?
Thanks.