use admin theme to render modules pages 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'     =&gt; ['page callback' =&gt; 'handle_foo', /*other opts*/],
        'admin/content/foo/bar' =&gt; ['page callback' =&gt; 'handle_foobar', /*other opts*/], 
        /* list goes on*/
    ];
 }

 function handle_foo() {
    return ['#theme' =&gt; 'handle_foo'];
 }

 function theme_handle_foo() {
    /*database logic here, then return compiled html to be rendered. */
    return '&lt;div&gt; I am a foo!&lt;/div&gt;';
 }


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'   =&gt; TRUE,
    'admin/content/foo/*' =&gt; TRUE,
    '/admin/content/foo'  =&gt; 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)
I found 2 solutions to this:

Solution one

Use hook_custom_theme(): see hook_custom_theme()

function mymodule_custom_theme() {
 $use_admin = workout_when_you_want_to_use_admin(); //true or false
 if ($use_admin)
   return variable_get('admin_theme');
}


Solution 2 (preferred)

Ensure that the user account has the permission View the administration theme attached to their role.