I want my custom module pages to be rendered using the admin theme, at the moment they only render using the admin theme for User 1 (see below).
I have a module called mymodule
that defines many administrative views. It's setup in the following structure:
function mymodule_menu() {
return [
'admin/content/foo' => ['page callback' => 'handle_foo', /*other opts*/],
'admin/content/foo/bar' => ['page callback' => 'handle_foobar', /*other opts*/],
/* list goes on*/
];
}
function handle_foo() {
return ['#theme' => 'handle_foo'];
}
function theme_handle_foo() {
/*database logic here, then return compiled html to be rendered. */
return '<div> I am a foo!</div>';
}
Say I have 2 users:
- User 1: All permissions available(including administration)
- User 2: 1 custom permission defined in the module
When logged in as User 1, all pages that follow admin/*
are rendered with the drupal admin_theme
including mymodule
paths.
When logged in as User 2 all of mymodule
pages are rendered using the frontend theme.
I've tried using hook_admin_paths but this doesn't work:
function mymodule_admin_paths() {
return [
'admin/content/foo' => TRUE,
'admin/content/foo/*' => TRUE,
'/admin/content/foo' => TRUE,
];
}
I have also read on here that any path that follows the admin/*
convention should use the admin_theme
by default which appears to be true for user 1 but not user 2.
My take on this is that I need to give user 2 some kind of permission, however I don't want them to be able to do anything other than login and access the paths set out in mymodule
(I don't want to use 3rd party modules)