Created
March 3, 2016 16:04
-
-
Save Raistlfiren/da08a112a2e36068f237 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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