Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace FA\Shared\CoreBundle\Handler;
use Doctrine\Common\Persistence\ObjectManager;
use FA\Shared\CoreBundle\Form\Handler\FormHandler;
class CreateHandler extends NewHandler
{
/**
* @var FormHandler $formHandler
*/
protected $formHandler;
/**
* @var ObjectManager $om
*/
protected $om;
public function __construct(ActionHandler $handler, FormHandler $formHandler, ObjectManager $om)
{
parent::__construct($handler, $formHandler);
$this->om = $om;
}
public function isFormProcessed($route)
{
$form = $this->getForm($route);
$form->handleRequest($this->handler->getRequest());
if ($form->isValid()) {
$this->save($this->handler->getEntity());
return true;
}
$this->handler->setOldForm($form);
return false;
}
public function save($entity)
{
$this->om->persist($entity);
$this->om->flush();
}
public function getEntity()
{
return $this->handler->getEntity();
}
public function getOldForm()
{
return $this->handler->getOldForm();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment