问题描述
我正在关注这里的文档:https://docs.sulu.io/en/2.2/cookbook/smart-content-data-provider.html
尝试为我的自定义实体类型“MatchEvent”创建自定义数据提供程序:
我是按照这里的解释做的。因为我有 services.yaml 文件,所以我像这样定义了这两个:
app.match_event_repository:
class: App\Repository\MatchEventRepository
factory: ['@doctrine','getRepository']
arguments:
- Symfony\Bridge\Doctrine\ManagerRegistry
app.smart_content.data_provider.matchevent:
class: App\SmartContent\MatchEventDataProvider
arguments: ['@app.match_event_repository','@sulu_core.array_serializer','@request_stack' ]
tags: [{name: 'sulu.content.type',alias: 'smart_matchevent_selection'}]
所以,如果我理解得很好,之后我应该有名为“smart_matchevent_selection”的自定义内容数据提供者,我可以这样使用它:
<property name="match" type="smart_content">
<meta>
<title lang="en">Match</title>
<title lang="de">Match</title>
</meta>
<params>
<param name="provider" value="smart_matchevent_selection"/>
</params>
</property>
但是当我尝试编辑包含此字段的页面时出现错误:
Sulu\Bundle\PreviewBundle\Controller\PreviewController 中缺少参数标记
在 project/vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Controller/PreviewController.php
处触发异常:
public function stopAction(Request $request): Response
{
$this->preview->stop($this->getRequestParameter($request,'token',true));
return new JsonResponse();
}
我在这里做错了什么?
解决方法
如果您仔细查看文档中 SmartContentDataProvider
的服务定义,您会注意到标签应该是 {name: 'sulu.smart_content.data_provider',alias: 'match_events'}
而不是 {name: 'sulu.content.type',alias: 'smart_matchevent_selection'}
...
然后你可以像<param name="provider" value="match_events"/>