[Drupal] Use administrative theme when deleting or reviewing the content node

本文介绍如何在Drupal中通过自定义模块实现删除或查看修订版本时保持在后台,而非跳转到前端的方法。通过实现hook_init()函数并设置主题为管理主题,可以确保在执行这些操作时留在后台。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As we know, in drupal, the frontend and backend are mixed together, but when we click the button "delete" or "revisions" of a node, we are redirected to frontend, so how can we set to stay in backend when doing that?

 

Thanks to the implement of drupal, we can hook the hook_init() function to do that. Here is a way to build a module called "my_admin_node"

 

About how to build a module in drupal, please google it :)

 

In the my_admin_node.module file, we write the code as below for example:

ContractedBlock.gifExpandedBlockStart.gif代码
<?php
// $Id:


/**
* Implementation of hook_init().
*/
function my_admin_node_init() {
// Use the administrative theme
$arg_2 = arg(2);
if (
$arg_2 == 'delete'
|| $arg_2 == 'revisions'
|| (arg(0) == 'user' && !empty($arg_2))
) {
global $custom_theme;
$custom_theme = variable_get('admin_theme', '0');
drupal_add_css(drupal_get_path(
'module', 'system') .'/admin.css', 'module');
}
}
so when we visit node/111/delete, we will still stay in backend but not redirected to frontend.

 

Have fun with drupal!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值