Borja Pombo
Borja Pombo

Reputation: 535

Events for custom resources?

I've created a new entity with ResourcesBundle but on the profiler I can't see the Events.

Must I create manualy?

Creating an EventListener for sylius.book.pre_create doesn't do nothing.

Adding Info

Hi anothertime lchrusciel.

This is my configuration for my resource:

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/

And on my bundle config I have this:

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

What I'm doing wrong then?

Upvotes: 1

Views: 719

Answers (1)

lchrusciel
lchrusciel

Reputation: 359

If it is your custom resource you should look for app.book.pre_create event.

As you can see here event name depends on application name which is sylius for predefined Sylius resources, but if you defined your own, it usually app.

If you have followed Sylius docs about using ResourceBundle with your own resources you have found following config:

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

So important part of this config is an alias of resource app.book. Dot split alias to application name(app) and resource name(book).

Same rules apply to crud generation config:

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

Using app as a application name is Sylius recommendation, but you can arbitrary choose any other.

Edit

In your example this is an important part:

sylius_resource:
    resources:
        dinamic.post:
            classes:

According to it, dinamic is an application name, and post is a resource name. So the following events should be triggered:

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

Upvotes: 3

Related Questions