Use node-menu on page

2019-09-08 17:21发布

I would like to use the node-menu (see image) on a page in Drupal.

enter image description here

Is this possible and, if yes, how?

标签: drupal menu
2条回答
淡お忘
2楼-- · 2019-09-08 18:05

Okay; a node page usually has those View and Edit tabs. So my next question is to wonder why they aren't appearing on your node page already. Have you by chance created a custom page template for this node type and removed the code that prints the tabs? Or is there a chance you're logged in as a user that doesn't have permission to edit this type of node?

There must be a reason why you're not getting those tabs; they should be there, by default.

If you do have a custom page template for this node type, look for code that looks something like this:

        <?php if ($tabs): ?>
          <div class="tabs"><?php print $tabs; ?></div>
        <?php endif; ?>

If you don't see code like that, try adding it.

If you DO see code like that, try to isolate what's different about this content type compared to other content types where you DO see those tabs.

查看更多
【Aperson】
3楼-- · 2019-09-08 18:16

If the page you are referring is a custom page output from your module, and "mymodule/page" is the path for that page, for which you want the tabs "View" and "Edit," then you should implement hook_menu() using code similar to the following one:

function mymodule_menu() {
  $items = array();

  $items['mymodule/page'] = array(
    'page callback' => 'mymodule_page_view', 
    'access arguments' => array('view mymodule page'),
  );

  $items['mymodule/page/view'] = array(
    'title' => 'View', 
    'type' => MENU_DEFAULT_LOCAL_TASK, 
    'weight' => -10,
  );
  $items['mymodule/page/edit'] = array(
    'title' => 'Edit', 
    'page callback' => 'mymodule_page_edit', 
    'access arguments' => array('edit mymodule page'), 
    'weight' => 0, 
    'type' => MENU_LOCAL_TASK, 
  );

  return $items;
}

If the page you are referring is a page that is shown at example.com/mymodule/page, and that should show what you see at example.com/node/7, then you can implement the following code, in Drupal 7:

function mymodule_url_inbound_alter(&$path, $original_path, $path_language) {
  if (preg_match('|^mymodule/page|', $path)) {
    $path = 'node/7';
  }
}

The equivalent for Drupal 6 is writing the following code in the settings.php file:

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  if (preg_match('|^mymodule/page|', $path)) {
    $result = 'node/7';
  }
}

I didn't write the symmetric code for hook_url_outbound_alter(), and custom_url_rewrite_outbound() as I suppose you are not interested in rewriting example.com/node/7 to make it appear as example.com/mymodule/page, but you are interested in making appear example.com/mymodule/page the same as example.com/node/7.

查看更多
登录 后发表回答