Calendar Typo3 cal(日历基)在外部扩展中使用事件对象
我正在做一个扩展,它取决于cal base。我通过抓取其他来源的网站来获取事件 我正在慢慢地转换到extbase,我想知道是否有可能或者如何从我的扩展访问calbase事件 我知道我可以使用mapOnProperty访问表。但我也必须重写整个逻辑 我想知道是否可以只使用calendar base的对象 我试着写一个测试:Calendar Typo3 cal(日历基)在外部扩展中使用事件对象,calendar,typo3,tdd,extbase,Calendar,Typo3,Tdd,Extbase,我正在做一个扩展,它取决于cal base。我通过抓取其他来源的网站来获取事件 我正在慢慢地转换到extbase,我想知道是否有可能或者如何从我的扩展访问calbase事件 我知道我可以使用mapOnProperty访问表。但我也必须重写整个逻辑 我想知道是否可以只使用calendar base的对象 我试着写一个测试: <?php class CalEventTest extends \TYPO3\CMS\Core\Tests\BaseTestCase { /**
<?php
class CalEventTest extends \TYPO3\CMS\Core\Tests\BaseTestCase {
/**
* @test
*/
public function anInstanceOfCalEventCanBeConstructed() {
$calEventService = & \TYPO3\CMS\Cal\Utility\Functions::getEventService ();
// $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
// $calEventService = $objectManager->get('TYPO3\CMS\Cal\Service\EventService');
// $calEventService = new TYPO3\CMS\Cal\Service\EventService();
// $events = $calEventService->findAll(array(1));
}
}
在尝试更多之前,我想知道这种方法是否可行。提到的错误似乎与测试环境上下文有关
我使用的是Typo3 6.2.27和cal 1.10.1。未经jet测试,但正如所述,您应该像这样访问EventService:
$storagePageID = 123;
/** @var \TYPO3\CMS\Cal\Service\EventService $eventService **/
$eventService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceService('tx_cal_phpicalendar', 'cal_event_model');
$events = $eventService->findAll($storagePageID);
我发现CALAPI看起来很有前途
/**
* @test
*/
public function calApiCanBeAccessed() {
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$calAPIPre = $objectManager->get('TYPO3\CMS\Cal\Controller\Api');
$this->assertInstanceOf(TYPO3\CMS\Cal\Controller\Api::class, $calAPIPre);
$this->assertObjectHasAttribute('prefixId', $calAPIPre);
$pidList = "1095, 80";
$calAPI = $calAPIPre->tx_cal_api_without($pidList);
$this->assertInstanceOf(TYPO3\CMS\Cal\Controller\Api::class, $calAPI);
$this->assertObjectHasAttribute('prefixId', $calAPI);
$this->assertInstanceOf(TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $calAPI->cObj);
}
并成功返回一个事件对象
/**
* @test
*/
public function calEventCanBeFoundThroughApi() {
$pidList = "1095, 80";
$eventUid = '2670';
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$calAPI = $objectManager->get('TYPO3\CMS\Cal\Controller\Api')->tx_cal_api_without($pidList);
$event = $calAPI->findEvent($eventUid, 'tx_cal_phpicalendar', $pidList);
$this->assertInstanceOf(TYPO3\CMS\Cal\Model\Eventmodel::class, $event);
}
在内部,它似乎使用模拟TSFE上下文的方法,如果没有cObj存在,我没有使用现有的cObj尝试tx_cal_api_和&$cObj,&$conf方法 阅读了2012年的一篇旧文章后,我在Typo3 6.2设置中实现了:
<?php
class CalEventTest extends \TYPO3\CMS\Core\Tests\BaseTestCase {
/**
* @test
*/
public function anInstanceOfCalEventCanBeConstructed() {
$rightsObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry ('basic', 'rightscontroller');
$rightsObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceService('cal_rights_model', 'rights');
$rightsObj->setDefaultSaveToPage();
$modelObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','modelcontroller');
$modelObj = new \TYPO3\CMS\Cal\Controller\ModelController();
$viewObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','viewcontroller');
$viewObj = new \TYPO3\CMS\Cal\Controller\ViewController();
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$configurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface');
$controller = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','controller');
$controller = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Controller\\Controller');
$cObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','cobj');
$cObj = $configurationManager->getContentObject();
$cObj = new TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer();
$GLOBALS['TSFE'] = new \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController($GLOBALS['TYPO3_CONF_VARS'], $pid, '0', 1, '', '', '', '');
$GLOBALS['TSFE']->cObj = $cObj;
$GLOBALS['TSFE']->sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
$storagePageID = "1095, 80";
$eventService = & \TYPO3\CMS\Cal\Utility\Functions::getEventService ();
if ($eventService) {
$events = $eventService->findAll($storagePageID);
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('2', $this->getDebugId()."-".__FUNCTION__, -1, array($events, $eventService->getServiceKey ()) );
}
}
}
这很管用,但我觉得它非常难看。下一步我将尝试cal api
这是对我的问题的编辑,但实际上是一个答案谢谢你给我指手册。没想到会在那里讨论这个问题。我试过你的建议。请求eventService时它没有失败,这是向前迈出的一大步,但我还没有得到一个。我将从这一点开始做一些工作。\TYPO3\CMS\Cal\Utility\Functions::getEventService;利用这种方法,但需要一个巨大的初始化过程,如上所述。
<?php
class CalEventTest extends \TYPO3\CMS\Core\Tests\BaseTestCase {
/**
* @test
*/
public function anInstanceOfCalEventCanBeConstructed() {
$rightsObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry ('basic', 'rightscontroller');
$rightsObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceService('cal_rights_model', 'rights');
$rightsObj->setDefaultSaveToPage();
$modelObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','modelcontroller');
$modelObj = new \TYPO3\CMS\Cal\Controller\ModelController();
$viewObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','viewcontroller');
$viewObj = new \TYPO3\CMS\Cal\Controller\ViewController();
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$configurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface');
$controller = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','controller');
$controller = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Controller\\Controller');
$cObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','cobj');
$cObj = $configurationManager->getContentObject();
$cObj = new TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer();
$GLOBALS['TSFE'] = new \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController($GLOBALS['TYPO3_CONF_VARS'], $pid, '0', 1, '', '', '', '');
$GLOBALS['TSFE']->cObj = $cObj;
$GLOBALS['TSFE']->sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
$storagePageID = "1095, 80";
$eventService = & \TYPO3\CMS\Cal\Utility\Functions::getEventService ();
if ($eventService) {
$events = $eventService->findAll($storagePageID);
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('2', $this->getDebugId()."-".__FUNCTION__, -1, array($events, $eventService->getServiceKey ()) );
}
}
}