Php Drupal-Set';用户/%/编辑/删除文件';在';用户/%/编辑';
我正在使用内容配置文件模块。当用户在查看个人资料页面上并按edit时,他们希望显示个人资料编辑页面,而不是现在的帐户设置。内容配置文件编辑页面的路径为“user/%/edit/file”。有人知道如何将“user/%/edit/uprofile”设置为“user/%/edit”的默认选项卡吗?edit 2(用于内容配置文件) 此示例适用于“内容配置文件”选项卡。只需将Php Drupal-Set';用户/%/编辑/删除文件';在';用户/%/编辑';,php,drupal,menu,Php,Drupal,Menu,我正在使用内容配置文件模块。当用户在查看个人资料页面上并按edit时,他们希望显示个人资料编辑页面,而不是现在的帐户设置。内容配置文件编辑页面的路径为“user/%/edit/file”。有人知道如何将“user/%/edit/uprofile”设置为“user/%/edit”的默认选项卡吗?edit 2(用于内容配置文件) 此示例适用于“内容配置文件”选项卡。只需将$type更改为配置文件内容类型的短名称。这还展示了如何清理代码以供实际使用(我之前的示例非常非常冗长): 将功能的第二部分替换为
$type
更改为配置文件内容类型的短名称。这还展示了如何清理代码以供实际使用(我之前的示例非常非常冗长):
将功能的第二部分替换为菜单项的设置,您应该处于良好状态。当然,在对菜单进行任何更改后,请记住清除缓存以使其生效。以下是我在安装内容配置文件和默认内容类型(“配置文件”)时使用的代码: 更改
$userprofile=$items['user/%user\u category/edit/profile']
以匹配所需的内容配置文件路径(在您的情况下,这将是$userprofile=$items['user/%user\u category/edit/profile']
另外,请确保您的模块在内容配置文件模块之后运行(您的模块的“权重”必须大于-1,即内容配置文件模块的权重)。模块的默认权重为0,因此您在那里应该没有问题。drupal.org上有一个模块。 使用配置文件字段。
请参阅。我正在寻找解决方案,但对如此复杂的问题并不满意。我就是这样做的
function MYTHEME_menu_link(array $variables) {
global $user;
if($variables["element"]["#theme"] == "menu_link__user_menu" && $variables["element"]["#original_link"]["router_path"] == "user") {
$variables["element"]["#href"] = "user/".$user->uid."/edit";
}
return theme_menu_link($variables);
}
哇,这么小的东西有这么多代码:)谢谢所有关于drupal菜单系统的额外信息!我觉得很困惑。不幸的是,这个代码不适合我。我收到一个php错误,上面写着:“无法在第346行的menu.inc中打开所需的'modules/user/node.pages.inc'。在内容配置文件模块中有一个钩子菜单改变了它;我的例子是core的简介。我已经编辑了我的回复,并为内容概要文件添加了一个新的示例。我之前的示例过于冗长,无法解释清楚,但这个新示例展示了如何清理代码。这是我迄今为止关于堆栈溢出的最佳答案,因为它提供了非常丰富的信息,并且我找到了重构代码的好方法。我正在学习php,所以我觉得这非常有用。非常感谢!回答得很好,马克@Toxid:对于一件小事来说,它似乎有很多代码,但这可能是因为Drupal菜单系统不仅仅是在页面上显示菜单项。事实上,菜单系统是Drupal中的一个重要组件,它处理所有请求,检查访问权限,包括所需的文件,将它们路由到适当的函数,并在线路的某个位置创建可见的菜单项。这就是为什么单个菜单项在代码中定义了这么多属性。
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']);
}
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']);
}
function mymodule_menu_alter(&$items) {
// Save the data from user/%/edit into user/%/edit/account.
$items['user/%user_category/edit/account'] = $items['user/%user_category/edit'];
$items['user/%user_category/edit/account']['tab_parent'] = 'user/%/edit';
$items['user/%user_category/edit/account']['title'] = 'Account';
// Change the default user/%/edit to user/%/edit/profile.
$useredit = &$items['user/%user_category/edit'];
$userprofile = &$items['user/%user_category/edit/profile'];
$useredit['page callback'] = $userprofile['page callback'];
$useredit['page arguments'] = $userprofile['page arguments'];
$useredit['access callback'] = $userprofile['access callback'];
$useredit['access arguments'] = $userprofile['access arguments'];
$useredit['file'] = $userprofile['file'];
$useredit['file path'] = $userprofile['file path'];
// Make the user/%/edit/profile sub-tab the default and left-most sub-tab.
$userprofile['type'] = MENU_DEFAULT_LOCAL_TASK;
$userprofile['weight'] = -10;
}
function MYTHEME_menu_link(array $variables) {
global $user;
if($variables["element"]["#theme"] == "menu_link__user_menu" && $variables["element"]["#original_link"]["router_path"] == "user") {
$variables["element"]["#href"] = "user/".$user->uid."/edit";
}
return theme_menu_link($variables);
}