我想覆盖Extbase控制器,例如TYPO3 v10.4中的新闻。因此,我在ext_locaconf.php 中注册了一个XClass
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][GeorgRingerNewsControllerNewsController::class] = [
'className' => ClickstormCsEventsControllerEventController::class
];
之后,我想注入我的新存储库
/**
* eventDateRepository
*
* @var EventDateRepository
*/
protected $eventDateRepository = null;
/**
* Inject a eventDateRepository
*
* @param EventDateRepository $eventDateRepository
*/
public function injectEventDateRepository(EventDateRepository $eventDateRepository)
{
$this->eventDateRepository = $eventDateRepository;
}
但是我的eventDateRepository为null。当我使用构造函数时也是如此。
尽管我不知道这种行为的原因,但一个可持续的解决方法是在initializeAction
方法中手动实例化依赖项。
就我而言,这就是我所写的:
/**
* @var TYPO3CMSExtbaseServiceImageService
*/
protected $imageService;
public function initializeAction()
{
parent::initializeAction();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->imageService = $objectManager->get(TYPO3CMSExtbaseServiceImageService::class);
}