【问题标题】:Sulu: error when trying to use custom data providerSulu:尝试使用自定义数据提供程序时出错
【发布时间】:2021-05-26 09:28:53
【问题描述】:

我正在关注这里的文档: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();
}

我在这里做错了什么?

【问题讨论】:

    标签: sulu


    【解决方案1】:

    如果你仔细查看文档中SmartContentDataProvider的服务定义,你会注意到标签应该是{name: 'sulu.smart_content.data_provider', alias: 'match_events'}而不是{name: 'sulu.content.type', alias: 'smart_matchevent_selection'}...

    然后你可以像&lt;param name="provider" value="match_events"/&gt;一样使用它

    【讨论】:

    • 感谢您的快速回复。现在我收到错误,找不到“Symfony\Bridge\Doctrine\ManagerRegistry”。我应该如何定义“app.match_event_repository”的“参数”? “%sulu_example.example.entity%”到底是什么?
    • 你的实体的 fqcn 应该去那里,在你的情况下可能是 App\Entity\MatchEvent ...这不是特定于 sulu,这就是你为你的实体实例化学说的 EntityRepository 的方式
    • 但是您也可以创建一个特定的MatchEventDataProviderRepository 服务,它不从EntityRepository 扩展...然后您只需将EntityManager 作为服务参数传递并获取真正的存储库使用$entityManager-&gt;getRepository(MatchEvent::class) ...这完全取决于你
    • 谢谢卢卡。我想我非常接近。设置“App\Entity\MatchEvent”后,我可以看到编辑页面,但现在出现错误:“[Semantical Error] line 0, col 84 near 'type WHERE entity.id': Error: Class App\Entity\MatchEvent has没有关联命名类型”。那会是什么?我已经为存储库类实现了 DataProviderRepositoryInterface,但没有更改我的实体类。
    • 该错误是在 /var/www/html/vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Preview/Renderer/PreviewRenderer.php 第 197 行创建的
    猜你喜欢
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 2016-04-23
    相关资源
    最近更新 更多