0

I want to create a completely bespoke admin page for some custom functionality. I don't want to hack the concept into render arrays as it will get messy fast.

I've got a menu declaration with a callback function, in here I can include and render templates. Using buffer streams, however, this only renders the file i'm passing.

Is it possible and if so how, to extend Drupal's default admin layout (header/footer/scripts/css) and print my 'template' in where $page would normally go?

I know I could view source and copy the code required, but I feel that would be an awful approach so please don't suggest.


Attempted solution not working.

function MYMODULENAME_menu() {
    $items = array (
        'admin/content/xxx' => array(
            'title' => 'xxx',
            'page callback' => 'MYMODULENAME_timetable_admin',
            'access arguments' => array('access content'),
        )
    );

    return $items;
}


function xxx_theme() {
  return array(
    'funky_admin_page_content' => array(
      'variables' => array(),
    ),
  );
}

function xxx_funky_admin_page_content() {
    echo "hello world";
  return 'hello world';
}


function MYMODULENAME_timetable_admin() {
  return array(
    '#theme' => 'xxx',
  );
}

Hello world isn't found in view-source. So I can only gather that the function isn't firing. I've cleared caches several times. Am I missing something obvious?

1

Absolutely, it's quite straightforward.

You'll need a path for the page:

function MYMODULE_menu() {
  $items['admin/foo/bar'] = [
    'title' => 'Foo',
    'page callback' => 'MYMODULE_admin_page_callback',
    'access arguments' => ['whatever makes sense'],
  ];

  return $items;
}

A theme declaration:

function MYMODULE_theme() {
  return [
    'funky_admin_page_content' => [
      'variables' => [],
    ],
  ];
}

Your function to build/get the content. Note that you could also put this in a template file, see hook_theme() for more details.

function theme_funky_admin_page_content() {
  // Build your HTML, return it as a string.
}

And your page callback:

function MYMODULE_admin_page_callback() {
  return [
    '#theme' => 'funky_admin_page_content',
  ];
}
  • I've added an edit to the post, I tried your solution. Whilst it worked in part. I have the header/footer with a custom title. I can't get my content function working. Any ideas? – Kiee Jul 15 '16 at 9:11
  • Id' say the only problem is the last function, should be '#theme' => 'funky_admin_page_content' – Clive Jul 15 '16 at 9:27
  • Matched code like for like, its still ignoring the function funky_admin_page_content – Kiee Jul 15 '16 at 10:51
  • What do you mean by "ignoring"? How are you confirming it's not being run? Did you make sure the module is installed and clear Drupal's caches? – Clive Jul 15 '16 at 10:56
  • 1
    I'm not sure what to tell you, sorry. The above works fine for me, I just copy/pasted it into a local site and added return 'test'; to theme_funky_admin_page_content. As expected, /admin/foo/bar displays the admin theme with a single word "test" in the content – Clive Jul 15 '16 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.