gpt4 book ai didi

Drupal - 将 'user/%/edit/uprofile' 设置为 'user/%/edit' 上的默认选项卡

转载 作者:行者123 更新时间:2023-12-02 07:51:49 26 4
gpt4 key购买 nike

我正在使用内容配置文件模块。当用户在他们的查看个人资料页面上并按编辑时,他们希望显示个人资料编辑页面,而不是现在的帐户设置。内容配置文件编辑页面的路径是“user/%/edit/uprofile”。有谁知道如何将“user/%/edit/uprofile”设置为“user/%/edit”的默认选项卡?

最佳答案

编辑 2(针对内容配置文件)

此示例适用于内容配置文件选项卡。只需更改 $type到配置文件的内容类型的简称。这也展示了如何清理代码以供实际使用(我之前的示例非常非常冗长):

function mymodule_menu_alter(&$items) {
// Specify the content profile type you'd like to work with
$type = 'profile';

// Make sure the user has a Content Profile to edit
if (!empty($items['user/%user_category/edit/' . $type])) {
// Pull out the menu items we want to modify.
$account = &$items['user/%user_category/edit/account'];
$edit = &$items['user/%user_category/edit'];
$profile = &$items['user/%user_category/edit/' . $type];

// Specify the Edit Account page as just a regular tab.
// You do not need to change this block: this will always be the same as long
// as you don't want Edit account to be the default tab.
$account = array(
'type' => MENU_LOCAL_TASK,
'page callback' => $edit['page callback'],
'page arguments' => $edit['page arguments'],
'access callback' => $edit['access callback'],
'access arguments' => $edit['access arguments'],
'module' => $edit['module'],
'file' => $edit['file'],
) + $account;

// Change the default action to take when hitting user/<UID>/edit to
// the content profile
$edit = array(
'page callback' => $profile['page callback'],
'page arguments' => $profile['page arguments'],
'access callback' => $profile['access callback'],
'access arguments' => $profile['access arguments'],
'file' => $profile['file'],
'file path' => $profile['file path'],
) + $edit;

// Specify the profile page as the default tab and remove settings
// already set above
$profile['type'] = MENU_DEFAULT_LOCAL_TASK;
unset($profile['page callback'],
$profile['page arguments'],
$profile['access callback'],
$profile['access arguments'],
$profile['file'],
$profile['file path']);
}
}

编辑 1(针对 Core 的配置文件模块)

我没有意识到您想要更改编辑 下的默认选项卡。它与我在下面描述的一般原则相同,但有一些小的修改。此示例将使个人 选项卡(位于 user/<UID>/edit/Personal )成为默认选项卡,而不是帐户选项卡:

function mymodule_menu_alter(&$items) {
// Specify the Edit Account page as just a regular tab.
// You do not need to change this block: this will always be the same as long
// as you don't want Edit account to be the default tab.
$items['user/%user_category/edit/account']['type'] = MENU_LOCAL_TASK;
$items['user/%user_category/edit/account']['page callback'] = $items['user/%user_category/edit']['page callback'];
$items['user/%user_category/edit/account']['page arguments'] = $items['user/%user_category/edit']['page arguments'];
$items['user/%user_category/edit/account']['access callback'] = $items['user/%user_category/edit']['access callback'];
$items['user/%user_category/edit/account']['access arguments'] = $items['user/%user_category/edit']['access arguments'];
$items['user/%user_category/edit/account']['module'] = $items['user/%user_category/edit']['module'];
$items['user/%user_category/edit/account']['file'] = $items['user/%user_category/edit']['file'];

// Change default action to take when hitting user/<UID>/edit to
// the settings of the page you want to use.
// -- Custom settings start here --
$items['user/%user_category/edit']['page callback'] = $items['user/%user_category/edit/Personal']['page callback'];
$items['user/%user_category/edit']['page arguments'] = $items['user/%user_category/edit/Personal']['page arguments'];
$items['user/%user_category/edit']['access callback'] = $items['user/%user_category/edit/Personal']['access callback'];
$items['user/%user_category/edit']['access arguments'] = $items['user/%user_category/edit/Personal']['access arguments'];
$items['user/%user_category/edit']['module'] = $items['user/%user_category/edit/Personal']['module'];
$items['user/%user_category/edit']['file'] = $items['user/%user_category/edit/Personal']['file'];

// When loading a profile tab, user_edit needs two parameters. The second parameter is the name of the profile
// (i.e. Personal from user/<UID>/edit/Personal).
$items['user/%user_category/edit']['page arguments'] = array(1, 'Personal');

// Specify the Personal page as the default tab and remove settings
// already set above */
$items['user/%user_category/edit/Personal']['type'] = MENU_DEFAULT_LOCAL_TASK;
unset($items['user/%user_category/edit/Personal']['page callback']);
unset($items['user/%user_category/edit/Personal']['page arguments']);
unset($items['user/%user_category/edit/Personal']['access callback']);
unset($items['user/%user_category/edit/Personal']['access arguments']);
unset($items['user/%user_category/edit/Personal']['module']);
unset($items['user/%user_category/edit/Personal']['file']);
}

概述和概念

您可以使用 hook_menu_alter 执行此操作并更改特定选项卡的类型。

更改默认选项卡是一个有点痛苦的过程。基本上,默认选项卡会继承页面的所有属性,而无需选择任何选项卡。这允许用户转到 user/UID并获取查看页面,而无需直接转到 user/UID/view .

要更清楚地了解这一点,请查看 user_menu() Hook 实现。注意如何 $items['user/%user/view']很空,$items['user/%user_uid_optional']包含您希望在 $items['user/%user/view'] 下看到的所有设置.

因此,您首先要将 View 选项卡设置为常规选项卡:为此,您必须复制附加到 user/UID 的所有设置。菜单项并将它们放入 user/UID/view菜单项。

完成后,您将替换 user/UID 的设置使用要成为默认选项卡的选项卡的设置。

最后,您要取消默认选项卡的所有菜单项设置,因为它将继承 user/UID 的设置。 .

查看此代码,它使 Edit 选项卡成为默认选项卡:

function mymodule_menu_alter(&$items) {
// Specify the View page as just a regular tab.
// You do not need to change this block: this will always be the same as long
// as you don't want View to be the default tab.
$items['user/%user/view']['type'] = MENU_LOCAL_TASK;
$items['user/%user/view']['page callback'] = $items['user/%user_uid_optional']['page callback'];
$items['user/%user/view']['page arguments'] = $items['user/%user_uid_optional']['page arguments'];
$items['user/%user/view']['access callback'] = $items['user/%user_uid_optional']['access callback'];
$items['user/%user/view']['access arguments'] = $items['user/%user_uid_optional']['access arguments'];
$items['user/%user/view']['file'] = $items['user/%user_uid_optional']['file'];

// Normal tabs don't have a weight
unset($items['user/%user/view']['weight']);

// Change default action to take when hitting user/<UID> to
// the settings of the page you want to use.
// -- Custom settings start here --
$items['user/%user_uid_optional']['page callback'] = $items['user/%user_category/edit']['page callback'];
$items['user/%user_uid_optional']['page arguments'] = $items['user/%user_category/edit']['page arguments'];
$items['user/%user_uid_optional']['access callback'] = $items['user/%user_category/edit']['access callback'];
$items['user/%user_uid_optional']['access arguments'] = $items['user/%user_category/edit']['access arguments'];
$items['user/%user_uid_optional']['file'] = $items['user/%user_category/edit']['file'];

// Specify the Edit page as the default tab and remove settings
// already set above
$items['user/%user_category/edit']['type'] = MENU_DEFAULT_LOCAL_TASK;
$items['user/%user_category/edit']['weight'] = -10;
unset($items['user/%user_category/edit']['page callback']);
unset($items['user/%user_category/edit']['page arguments']);
unset($items['user/%user_category/edit']['access callback']);
unset($items['user/%user_category/edit']['access arguments']);
unset($items['user/%user_category/edit']['file']);
}

用您的菜单项的设置替换函数的第二部分,您应该处于良好状态。当然,记得在进行任何菜单更改后清除缓存以使它们生效。

关于Drupal - 将 'user/%/edit/uprofile' 设置为 'user/%/edit' 上的默认选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3408602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com