You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何判断TYPO3后端Web > Page模块是否处于激活状态?

解决TYPO3仅在Web > Page模块显示自定义按钮的问题

要判断当前是否处于Web > Page模块,核心是获取后端当前激活的模块标识——Web > Page模块的官方标识为web_layout,可以通过后端用户对象的模块数据来判断,具体实现如下:

在你的ModifyButtonBarEvent事件监听器类中,添加模块判断逻辑,只有当当前模块为web_layout时才添加按钮:

use TYPO3\CMS\Backend\Controller\Event\ModifyButtonBarEvent;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class CustomEditRecordButtonListener
{
    public function __invoke(ModifyButtonBarEvent $event): void
    {
        // 获取当前后端用户实例
        $backendUser = GeneralUtility::makeInstance(BackendUserAuthentication::class);
        // 获取Web模块组下当前激活的子模块标识
        $currentWebModule = $backendUser->getModuleData('moduleMenu', 'web');

        // 仅在Web > Page模块(标识web_layout)激活时执行后续逻辑
        if ($currentWebModule !== 'web_layout') {
            return;
        }

        // 以下是你原有的按钮创建逻辑
        $pageUid = (int)GeneralUtility::_GP('id');
        // 创建并添加"编辑自定义记录"按钮到按钮栏
        // ... 你的按钮代码
    }
}

补充说明

  • web_layout是TYPO3官方定义的Web > Page模块唯一标识,不会随版本轻易变更
  • 通过BackendUserAuthentication的getModuleData方法获取模块信息,比直接读取GET参数更可靠,能覆盖AJAX请求等特殊场景

内容的提问来源于stack exchange,提问作者cweiske

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 11:11:02