sonata-project / SonataPageBundle

This bundle provides a Site and Page management through container and block services
https://docs.sonata-project.org/projects/SonataPageBundle
MIT License
219 stars 210 forks source link

Add EventDispatcher after create a snapshot #1317

Closed eerison closed 2 years ago

eerison commented 3 years ago

Add EventDispatcher after update or create an snapshot

after create a snapshot I will dispatch an event to be able create listeners for who implement this lib.

e.g:

class SonataPageEvent
{
    public const CREATE_SNAPSHOT = 'sonata.page.create_snapshot';

    private $page;

    public function __construct(PageInterface $page)
    {
        $this->page = $page;
    }

    public function getPage(): PageInterface
    {
        return $this->page;
    }
}
$event = new SonataPageEvent($page);
$dispatcher->dispatch($event, SonataPageEvent::CREATE);

I'll put this after this line https://github.com/sonata-project/SonataPageBundle/blob/3.x/src/Controller/SnapshotAdminController.php#L67

eerison commented 3 years ago

let me know if does it make sense, if yes I'll open a Pull request :)

VincentLanglet commented 3 years ago

There is already the call $this->admin->create($snapshot);

Wouldn't it better to create an AdminExtension to dispatch action after every action create/edit/... The AdminExtension could be here: https://github.com/sonata-project/SonataAdminBundle/tree/3.x/src/Admin/Extension And then the SnapShot admin could use this admin extension.

eerison commented 3 years ago

@VincentLanglet Hmmm I don't fully understand how it works.

could you give any example?

VincentLanglet commented 3 years ago

If we're doing something like https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/Extension/LockExtension.php

Implementing all the PostCreate, PostUpdate, PostDelete, etc methods and dispatching an event inside.

Then, the admin class will call these method https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/AbstractAdmin.php#L616 if the Extension is added to the admin.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.