Skip to content

Instantly share code, notes, and snippets.

@Raistlfiren
Created March 3, 2016 16:04
Show Gist options
  • Save Raistlfiren/da08a112a2e36068f237 to your computer and use it in GitHub Desktop.
Save Raistlfiren/da08a112a2e36068f237 to your computer and use it in GitHub Desktop.
<?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