Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AdminListBundle] Add events to AdminListController #974

Merged
merged 1 commit into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Kunstmaan\AdminBundle\Event\Events;
use Kunstmaan\AdminListBundle\AdminList\AdminList;
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractAdminListConfigurator;
use Kunstmaan\AdminListBundle\Event\AdminListEvent;
use Kunstmaan\AdminListBundle\Event\AdminListEvents;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
Expand Down Expand Up @@ -132,8 +134,10 @@ protected function doAddAction(AbstractAdminListConfigurator $configurator, $typ
}

if ($form->isValid()) {
$this->container->get('event_dispatcher')->dispatch(AdminListEvents::PRE_ADD, new AdminListEvent($helper));
$em->persist($helper);
$em->flush();
$this->container->get('event_dispatcher')->dispatch(AdminListEvents::POST_ADD, new AdminListEvent($helper));
$indexUrl = $configurator->getIndexUrl();

return new RedirectResponse(
Expand Down Expand Up @@ -199,8 +203,10 @@ protected function doEditAction(AbstractAdminListConfigurator $configurator, $en
}

if ($form->isValid()) {
$this->container->get('event_dispatcher')->dispatch(AdminListEvents::PRE_EDIT, new AdminListEvent($helper));
$em->persist($helper);
$em->flush();
$this->container->get('event_dispatcher')->dispatch(AdminListEvents::POST_EDIT, new AdminListEvent($helper));
$indexUrl = $configurator->getIndexUrl();

return new RedirectResponse(
Expand Down Expand Up @@ -251,8 +257,10 @@ protected function doDeleteAction(AbstractAdminListConfigurator $configurator, $

$indexUrl = $configurator->getIndexUrl();
if ($request->isMethod('POST')) {
$this->container->get('event_dispatcher')->dispatch(AdminListEvents::PRE_DELETE, new AdminListEvent($helper));
$em->remove($helper);
$em->flush();
$this->container->get('event_dispatcher')->dispatch(AdminListEvents::POST_DELETE, new AdminListEvent($helper));
}

return new RedirectResponse(
Expand Down
30 changes: 30 additions & 0 deletions src/Kunstmaan/AdminListBundle/Event/AdminListEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Kunstmaan\AdminListBundle\Event;

use Symfony\Component\EventDispatcher\Event;

class AdminListEvent extends Event
{
/**
* @var object
*/
protected $entity;

/**
* AdminListEvent constructor.
* @param object $entity
*/
public function __construct($entity)
{
$this->entity = $entity;
}

/**
* @return object
*/
public function getEntity()
{
return $this->entity;
}
}
38 changes: 38 additions & 0 deletions src/Kunstmaan/AdminListBundle/Event/AdminListEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Kunstmaan\AdminListBundle\Event;

class AdminListEvents
{
/**
* When adding, triggered after the form is validated,
* but before the entity is persisted.
*/
const PRE_ADD = 'kunstmaan_admin_list.preAdd';

/**
* When adding, triggered after the entity is flushed.
*/
const POST_ADD = 'kunstmaan_admin_list.postAdd';

/**
* When editing, triggered after the form is validated,
* but before the entity is persisted.
*/
const PRE_EDIT = 'kunstmaan_admin_list.preEdit';

/**
* When editing, triggered after the entity is flushed.
*/
const POST_EDIT = 'kunstmaan_admin_list.postEdit';

/**
* When deleting, triggered before the entity is removed.
*/
const PRE_DELETE = 'kunstmaan_admin_list.preDelete';

/**
* When deleting, triggered after the remove is flushed.
*/
const POST_DELETE = 'kunstmaan_admin_list.postDelete';
}