自定义资源事件?

Events for custom resources?

我用 ResourcesBundle but on the profiler I can't see the Events 创建了一个新实体。

我必须手动创建吗?

sylius.book.pre_create 创建一个 EventListener 什么都不做。

添加信息

再见lchrusciel,你好。

这是我的资源配置:

dinamic_sylius_post:
    resource: |
        alias: dinamic.post
        path: blog/post
    type: sylius.resource

dinamic_sylius_admin_post:
    resource: |
        alias: dinamic.post
        section: admin
        templates: SyliusAdminBundle:Crud
        except: ['show', 'delete']
        redirect: index
        grid: dinamic_sylius_blog_post
    type: sylius.resource
    prefix: admin/

在我的捆绑包配置中,我有这个:

sylius_resource:
    resources:
        dinamic.post:
            classes:
                model: Dinamic\Bundle\SyliusBlogBundle\Entity\Post
                form:
                    default: Dinamic\Bundle\SyliusBlogBundle\Form\PostType

那我做错了什么?

如果这是您的自定义资源,您应该寻找 app.book.pre_create 事件。

如您所见,here 事件名称取决于应用程序名称,对于预定义的 Sylius 资源,它是 sylius,但如果您定义了自己的,通常是 app.

如果您遵循 Sylius 文档关于将 ResourceBundle 与您自己的资源一起使用,您会发现以下配置:

sylius_resource:
    resources:
        app.book:
            classes:
                model: AppBundle\Entity\Book

此配置的重要部分是资源 app.book 的别名。点将别名拆分为应用程序名称 (app) 和资源名称 (book)。

相同的规则适用于 crud 生成配置:

app_book:
resource: |
    alias: app.book
type: sylius.resource_api

Sylius 推荐使用 app 作为应用程序名称,但您可以任意选择其他名称。

编辑

在你的例子中这是一个重要的部分:

sylius_resource:
    resources:
        dinamic.post:
            classes:

据此,dinamic是应用名,post是资源名。因此应触发以下事件:

  • dinamic.post.pre_create
  • dinamic.post.post_create
  • dinamic.post.pre_update
  • dinamic.post.post_update
  • dinamic.post.pre_delete
  • dinamic.post.post_delete