在TYPO3 7.6.15中的FlexForm UserFunc中使用findAll清空结果

时间:2017-02-21 07:43:36

标签: repository extbase typo3-7.6.x

我在TYPO3 7.6.15中的FlexForm UserFunc中使用findAll得到一个空结果。 storagePid已设置,在前端我使用findAll获取所有结果。

这是我的UserFunc-Method:

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;
}

还有什么可以错?有人有想法吗?

1 个答案:

答案 0 :(得分: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);
    }

}