1

Let's say I have to create an extra users management views block for contributors role only, with some different columns, filters and actions available.

How do I create a simple page which is restricted to some roles only and automatically has the backend theming to put my views block in there? (I always put views blocks on pages, it makes editing views easier)

And last, how can I make that page appear in the admin toolbar as sub item of admin/people?

Do I have to write a custom module for that or maybe create a template file? Or is that maybe all in all a wrong approach?

2

I know there is already an accepted answer, which works perfectly fine, but I want to add an additional answer for those of us who arrive here from Google and, like me, need an answer based on php code that can be implemented in an custom module.

If you want to achieve the desired result, you can set your hook_menu entry to be of type MENU_LOCAL_TASK, this way the new page will be a new tab under the parent page, e.g. if the parent page is admin/people you set the path to admin/people/mytab:

function example_menu() {
  $items['admin/people/mytab'] = array(
    'title' => 'My Tab',
    'type' => MENU_LOCAL_TASK, // NB: this is a constant not a string
    // Etc.
  );
}

Now, regarding the theme: since this is under the admin/ path, it should use automatically the admin theme.

However if you still want to use a custom theme for this page, you can do it in code by setting theme_callback in your hook_menu entry. The corresponding callback function should return a string with the machine-readable name of the theme. E.g.

function example_menu() {
  $items['my/path'] = array(
    'title' => 'My Tab',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'my_page_callback',
    'theme callback' => 'my_theme_callback', // This is it.
  );

  return $items;
}

and the callback function:

function my_theme_callback() {
  return 'mytheme';
}
4

Easiest way I think of is to create a page display for you view. Set the path to admin/people/mypage and under the menu settings in views choose tab, give your menu item a title and keep the menu setting at Navigation as it defaults to.

Now if you navigate to admin/people you will see a new tab with your page and menu title.

In the views configuration you can add access restriction to your URL / menu item.

If you insist on not creating a page display and instead want to place your block on a page, without coding you own module I would use Panels and Page Manager. You will need the modules Ctools and Panels. Under structure and pages, create a new page and give it your URL, set it to have a menu item (as described in the Views example) and use Panels as variant type. Once your Panel is created you can place your block into any region available in the layout you choose.

  • 1
    The page display approach works. Is it the path (admin/...) that makes this page themed in admin theme? – leymannx Sep 9 '13 at 14:46
  • 2
    Yes. But the path admin/people/somthing also tells the menu system that it is a child to admin/people – Pontus Nilsson Sep 9 '13 at 14:47
  • How do you do it in code? We use git so we are not allowed to modify the structure using the UI – mastazi Mar 7 '17 at 22:47
  • @mastazi you export it in features and add the generated module to git – Pontus Nilsson Mar 9 '17 at 13:36

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.