Project

General

Profile

Actions

Bug #105496

closed

Create a backend module with Extbase according to documents leads to exception

Added by Alex Kellner 24 days ago. Updated 22 days ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Documentation
Target version:
-
Start date:
2024-10-28
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
13
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Following instructions on: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/HowTo/BackendModule/CreateModuleWithExtbase.html#backend-modules-template

A simple backend controller action in TYPO3 13.4.0 leads to:

Call to undefined method TYPO3\CMS\Backend\Template\ModuleTemplate::setContent()

The example controller in my case would look like:

<?php

declare(strict_types=1);
namespace In2code\Lux\Controller;
use TYPO3\CMS\Backend\Attribute\AsController;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

#[AsController]
final class AnalysisController extends ActionController
{
    public function __construct(
        protected readonly ModuleTemplateFactory $moduleTemplateFactory,
    ) {
    }

    public function dashboardAction(): ResponseInterface
    {
        $this->view->assign('someVar', 'someContent');
        $moduleTemplate = $this->moduleTemplateFactory->create($this->request);
        // Adding title, menus, buttons, etc. using $moduleTemplate ...
        $moduleTemplate->setContent($this->view->render());
        return $this->htmlResponse($moduleTemplate->renderContent());
    }
}

Actions #1

Updated by Garvin Hicking 22 days ago

  • Category set to Documentation
  • Status changed from New to Closed

Indeed this is missing in the docs. I've created an issue on the documentation tracker: https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/issues/4962

The old moduleTemplate API has been removed: https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Deprecation-96903-DeprecateOldModuleTemplateAPI.html

Most likely you should be able to use:

 public function dashboardAction(): ResponseInterface
    {
        $moduleTemplate = $this->moduleTemplateFactory->create($this->request);
        $moduleTemplate->assign('someVar', 'someContent');
        return $moduleTemplate->renderResponse('MyTemplate');
    }

with an accompanying Layout file as outlined in https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Feature-96730-SimplifiedExtbackendModuleTemplateAPI.html

HTH!

Actions

Also available in: Atom PDF