Score:0

How can I customize an administrative view template from a custom module?

us flag

I created a view with a page display whose path is /admin/content/noun, and whose format is table. I'd like to override the table template with views-view-table--the-view-name--the-display-id.html.twig. The view's path means the view is displayed in the admin theme. Where do I put the template?

Creating a Claro's sub-theme doesn't work. Customizing web/core/themes/claro/templates/classy/views/views-view-table.html.twig works, but that's hacking core.

4uk4 avatar
cn flag
Sub-theming is the way to go, to avoid hacking core. Tested `drush generate theme` for the base theme `claro` and it installed just fine. You might only need to clean up the block layout.
us flag
`drush generate theme` with a base theme of claro creates a almost blank file structure from Claro in my themes directory. Enabling "claro_custom" one time is enough to show me that this is not a direction we would want to go in. I updated hook_theme_registry_alter() from https://drupal.stackexchange.com/questions/1249/how-do-i-override-a-default-view-template-from-another-module, but now the table from the view display contains no values, only my customizations which are outside the table. Still trying to get hook_theme() to work.
leymannx avatar
ne flag
After you enabled the theme and set it as default backend theme you may need to adjust the blocks, like re-placing them the same way they were in original Claro. The sub-theme is empty, yes, because all the parent files live in original Claro and you now in your sub-theme add only those again you want to customize. (Overriding the template from a custom module is easier IMHO.)
us flag
I definitely prefer to override the template from a custom module. But what's the base hook for a views template override? I can't tell from views_theme().
us flag
The 'base hook' is 'views_view_table'. Here's the code. ```/** * Implements hook_theme(). */ function mymodule_theme($existing, $type, $theme, $path) { return [ 'views_view_table__my_view__my_admin_table' => [ 'base hook' => 'views_view_table', ], ]; }```
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.