在TYPO3中通过“关闭按钮”链接到BE模块“页面布局”

问题描述 投票:0回答:1

可以链接到 TYPO3 中的后端模块页面布局(/web/layout),并带有返回 URL 和关闭按钮。

特别是,我有一个列表(例如 linkvalidator 中的损坏链接列表),并且想要跳转到页面布局视图,但可以再次跳回来 - 否则如果跳转到视图,会非常尴尬然后就跳不回来了。

左侧按钮会跳转到页面布局视图,但之后没有关闭或返回的按钮。

右键将打开一个编辑表单,其中还有一个“关闭”按钮。这也是我想要的另一件。

<f:variable name="link"><be:moduleLink route="web_layout" arguments="{id: element.pid, returnUrl: returnUrl}">layout</be:moduleLink></f:variable>
<a href="{link}" class="btn btn-default" title="page layout">
  <core:icon identifier="actions-document" size="small"/>
</a>
<be:link.editRecord class="btn btn-primary" title="edit"                                                     uid="{element.uid}" table="tt_content" returnUrl="{returnUri}">
  <core:icon identifier="actions-document-edit" size="small"/>
</be:link.editRecord>

“returnUrl”已在控制器中正确创建。

我已经调查过:两个 Viewhelpers 都会使用

UriBuilder::buildUriFromRoute
,它接受参数列表,包括 returnUrl。所以问题可能是,页面布局没有考虑从其他地方打开它的可能性,并且应该显示关闭按钮。但我认为,这是可以做到的,只是不知道如何做到。

typo3 fluid
1个回答
0
投票

假设您使用TYPO3 12。(提问时请务必添加有关您运行系统的信息。)

看一下 PageLayoutController:
TYPO3\CMS\后端\控制器\PageLayoutController

似乎没有可以使用的关闭/返回链接。
但是事件“ModifyPageLayoutContentEvent”是在控制器的 mainAction 中触发的。
您可以使用此事件来实现您的关闭/返回链接。

为此,您需要在以下位置注册一个事件侦听器:
your-ext/Configuration/Services.yaml
像这样:

services:
  VENDOR\YourExt\EventListener\PageLayoutListener:
    tags:
      - name: event.listener
        identifier: your-ext/page-layout-listener

然后你可以像这样实现事件监听器:

<?php
declare(strict_types = 1);
namespace VENDOR\YourExt\EventListener;

use TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class PageLayoutListener
{
    public function __invoke(ModifyPageLayoutContentEvent $event): void
    {
        $refererUrl = $_SERVER["HTTP_REFERER"];

        // Somehow you need to check from which Page you come,
        // so that the Close-Link is not shown, when opening the web/layout module directly
        // Here its assumed that the referer URL is the linkvalidator-reports page
        // You need at least PHP 8 when using str_contains function. If you run PHP<8 you need to use substr or other function
        if(str_contains($refererUrl, 'typo3/module/page/link-reports'))
        {
            $view = $event->getModuleTemplate();
            $buttonBar = $view->getDocHeaderComponent()->getButtonBar();
            $iconFactory = GeneralUtility::makeInstance(IconFactory::class);

            $returnButton = $buttonBar->makeLinkButton()
                ->setHref($refererUrl)
                ->setTitle('Close')  // Here you could use translation if needed like this: $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage')
                ->setIcon($iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))  // Create your custom icon or use any of the alredy created icons
                ->setShowLabelText(true);
            $buttonBar->addButton($returnButton, ButtonBar::BUTTON_POSITION_LEFT, 0);
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.