- π¨π¦Canada dallen33
@SoCalErich Would you mind posting an example of how you accomplished this?
- πΊπΈUnited States socalerich
Hey sorry I was out of town. So I basically created a custom module called admin_template_overrides. In my .module file I added a hook_theme function like this:
<?php function admin_template_overrides_theme($existing, $type, $theme, $path) { return [ 'paragraph__basic_text__default' => [ 'template' => 'paragraph--basic-text--default', 'base hook' => 'paragraph' ], 'paragraph__accordion' => [ 'template' => 'paragraph--accordion', 'base hook' => 'paragraph' ], 'paragraph__accordion_item' => [ 'template' => 'paragraph--accordion-item', 'base hook' => 'paragraph' ], ]; }
I have many more paragraph templates in my actual site, but this is a watered down version for simplicity.
So this looks for specific theme templates and specifies which template in my custom module to use for it as an override. For my use case, I am specifically overriding paragraph templates. You may need to change the "base hook" value to something else if you are not doing this for paragraphs.
Then I created a templates directory in my custom module that has all the various templates that I need except all I do is extend my front end themes template. This way I don't have to have the template code in two different places. I can essentially edit my front end theme template and the custom module will just automatically extend it. This may not be the BEST way to do this, but it is working and doing what I needed.
So, for example, I have a file in the templates directory of my custom module called "paragraph--basic-text--default.html.twig" and all it has in the file is:
{% extends "@uswds_base_subtheme/paragraphs/paragraph--basic-text--default.html.twig" %}
where @uswds_base_subtheme is my front end theme.
- πΊπΈUnited States alexi721
Erich, thank you so much for providing a detailed example on how to get the front-end templates activated in the edit form generated by the 'Layout Paragraphs' module. This is very helpful and worked great.
To make it even better I also imported the styles from the front-end theme by adding the following function to the .module file:
<?php function admin_template_overrides_form_alter(&$form, FormStateInterface $form_state, $form_id) { switch ($form_id) { case 'node_page_edit_form': // attach the library from the frontend theme $form['#attached']['library'][] = '<uswds_base_subtheme>/global'; break; } }
The only drawback is that the fonts of the Gin theme get overwritten by the fonts of the front-end theme.
@SoCalErich, did you come up with a way to avoid the font replacement of the Gin theme?
Thanks again for sharing your insights with the community.