在TYPO3 8.x中注册后端模块,从TYPO3 4.x升级

时间:2017-10-26 05:54:22

标签: typo3 typo3-6.2.x typo3-extensions typo3-8.x typo3-4.5

我在TYPO3 4.x中使用Backened模块(EXT:wec_map)进行扩展,

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule(
    'tools','txwecmapM1',
    '',
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('wec_map').'Classes/Module/MapAdministration/'
);

现在,我将TYPO3 4.x升级为TYPO3 8.7.8。我遇到了后端模块的问题,它在工具菜单组中显示空白区域。我已经替换了弃用的模块注册方法,如下所示:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
    'txwecmapM1',
    'tools', // Make module a submodule of 'web'
    'txwecmapM1', // Submodule key
    '', // Position
    [
        'access' => 'user,group',
        'icon'   => 'EXT:' . $extKey . '/Resources/Public/Icons/user_mod_bewebuser.svg',
        'labels' => 'LLL:EXT:' . $extKey . '/Resources/Private/Languages/Module/MapAdministration/locallang_mod.xlf',
    ]
);

它工作得很好,但图标显示默认的typo3图标,标签显示“:mlang_labels_tablabel”。谁能帮助我呢?

第二件事,我点击模块显示:

"Could not analyse class: "Tx_TxwecmapM1_Controller_accessController" maybe not loaded or no autoloader? Class Tx_TxwecmapM1_Controller_accessController does not exist"

请帮帮我......

2 个答案:

答案 0 :(得分:0)

模块定义对我来说完全没问题 -
但是AFAIK,它应该是$_EXTKEY而不是$extKey

哦,第二个问题可能是因为没有在这里使用命名空间。

这应该这样做:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
    'Vendor.' . $_EXTKEY,
    'tools', // Make module a submodule of 'web'
    'txwecmapM1', // Submodule key
    '', // Position
    [
        'access' => 'user,group',
        'icon'   => 'EXT:' . $_EXTKEY . '/Resources/Public/Icons/user_mod_bewebuser.svg',
        'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Languages/Module/MapAdministration/locallang_mod.xlf',
    ]
);

答案 1 :(得分:0)

聚会晚了一点,但仍然是这样做的方法(这要比typo3松弛)。

在扩展了\TYPO3\CMS\Backend\Module\BaseScriptClass的类/控制器中创建一个控制器,并添加以下功能:

function loadMCONF()
{
    $this->MCONF = $GLOBALS['TBE_MODULES']['_configuration']['myext_mymoduleM1'];
}

function init()
{
    $this->loadMCONF();
    parent::init();

    $this->getBackendUser()->modAccess($this->MCONF, 1);
    $this->pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
    $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
}


public function mainAction(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response)
{
    $this->postVars = $request->getParsedBody();
    $this->init();
    $this->main();
    $response->getBody()->write($this->content . $this->doc->endPage());
    return $response;
}`

那样,您可以从main()和init()中回收大部分旧代码。

使用addModule注册模块:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule(
    'myext',
    'mymoduleM1',
    '',
    '',
    [
        'routeTarget' => \MyVendor\MyExt\Controller\BackendModuleController::class . '::mainAction',
        'access' => 'admin',
        'name' => 'myext_mymoduleM1',
        'labels' => [
            'tabs_images' => [
                'tab' => 'EXT:myext/Resources/Public/Icons/BackendModule.svg',
            ],
            'll_ref' => 'LLL:EXT:myext/Resources/Private/Language/locallang_mod.xml',
        ]
    ]
);