我在 TYPO3 7.6.15 的 FlexForm UserFunc 中使用 findAll 得到空结果。 storagePid 已设置,在前端我使用 findAll 获得所有结果。
这是我的 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;
}
还有什么问题吗?有人有想法吗?
我找到了问题和合适的解决方案。
问题是,配置的 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);
}
}