Typo3 cal(日历基础)在外部扩展中使用事件对象
Typo3 cal (calendar Base) use event objects in foreign extension
我正在开发一个依赖于 cal base 的扩展。我通过抓取其他来源的网站来获取事件。
我正在慢慢转换到 extbase,我想知道是否可以或如何从我的扩展访问校准基础事件。
我知道我可以使用 mapOnProperty 访问表。但那样我也必须重写整个逻辑。
我想知道是否可以只使用日历基础的对象。
我试着写了一个测试:
<?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));
}
}
您看到不同的尝试被注释掉了。他们都以一种或另一种方式失败了。 CalEventService 看起来很有前途,但它也不起作用。最后一种方法的错误是。
Call to a member function isLoggedIn() on null in /var/www/clients/client4/web47/web/typo3conf/ext/cal/Classes/Service/NearbyEventService.php on line 27
我想知道在尝试更多之前这种方法是否可行(提到的错误似乎与测试环境上下文有关)。
我使用的是 Typo3 6.2.27 和 cal 1.10.1。
未经喷气测试,但正如 Manual 所说,您应该像这样访问 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);
我找到了看起来很有前途的校准 API
/**
* @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);
}
并成功returns一个事件对象
/**
* @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_with(&$cObj, &$conf)
方法)。
阅读了 2012 年的旧线程 (https://forum.typo3.org/index.php/t/192263/) 我在我的 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。
(这是对我的问题的修改,但它实际上是一个答案)
我正在开发一个依赖于 cal base 的扩展。我通过抓取其他来源的网站来获取事件。
我正在慢慢转换到 extbase,我想知道是否可以或如何从我的扩展访问校准基础事件。
我知道我可以使用 mapOnProperty 访问表。但那样我也必须重写整个逻辑。
我想知道是否可以只使用日历基础的对象。
我试着写了一个测试:
<?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));
}
}
您看到不同的尝试被注释掉了。他们都以一种或另一种方式失败了。 CalEventService 看起来很有前途,但它也不起作用。最后一种方法的错误是。
Call to a member function isLoggedIn() on null in /var/www/clients/client4/web47/web/typo3conf/ext/cal/Classes/Service/NearbyEventService.php on line 27
我想知道在尝试更多之前这种方法是否可行(提到的错误似乎与测试环境上下文有关)。
我使用的是 Typo3 6.2.27 和 cal 1.10.1。
未经喷气测试,但正如 Manual 所说,您应该像这样访问 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);
我找到了看起来很有前途的校准 API
/**
* @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);
}
并成功returns一个事件对象
/**
* @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_with(&$cObj, &$conf)
方法)。
阅读了 2012 年的旧线程 (https://forum.typo3.org/index.php/t/192263/) 我在我的 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。
(这是对我的问题的修改,但它实际上是一个答案)