2017-02-21 61 views
0

TYPO3 7.6.15中的FlexForm UserFunc中的findAll得到空結果。 storagePid已設置,在前端我用findAll獲得所有結果。TYPO3中的FlexForm UserFunc中findAll的空結果7.6.15

這裏是我的UserFunc法:

public function getBuldingOptions(&$config) 
{ 
    /** @var ObjectManager $om */ 
    $om = GeneralUtility::makeInstance(ObjectManager::class); 

    /** @var BuildingRepository $repo */ 
    $repo = $om->get(BuildingRepository::class); 
    $building = $repo->findAll(); 

    DebuggerUtility::var_dump($building, '$building'); // Output: TYPO3\CMS\Extbase\Persistence\Generic\QueryResultprototypeobject (empty) 

    // add empty value option 
    $config['items'][] = [LocalizationUtility::translate('BuildingUserFunc.building.emtpyValue', $this->extName), 0]; 

    /** @var Building $entity */ 
    foreach ($building as $entity) { 
     $config['items'][] = [$entity->getName(), $entity->getUid()]; 
    } 

    return $config; 
} 

能有什麼用還是錯?任何人有個想法?

回答

0

我發現了問題和合適的解決方案。

問題是,配置的storagePid在插件配置範圍中不起作用。您必須手動解決storagePid。

我已經寫了一個服務,並添加到EXT:xm_tools:

https://github.com/xima-media/xm_tools/blob/rc-1.0.0/Classes/Extensionmanager/ExtensionUtility.php

我的倉庫有initializeObject方法:

use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; 
use TYPO3\CMS\Extbase\Persistence\Repository; 
use Xima\XmTools\Extensionmanager\ExtensionUtility; 

class BaseRepository extends Repository 
{ 

    private $extName = 'my_extension_key'; 

    public function initializeObject() 
    { 
     $pluginSetup = ExtensionUtility::getTypoScriptPluginSetup($this->extName); 

     /** @var Typo3QuerySettings $querySettings */ 
     $querySettings = $this->objectManager->get(Typo3QuerySettings::class); 
     $querySettings->setStoragePageIds(array_merge($querySettings->getStoragePageIds(), explode(',', $pluginSetup['persistence']['storagePid']))); 
     $this->setDefaultQuerySettings($querySettings); 
    } 

} 
相關問題