Skip to content

Commit

Permalink
Merge pull request #342 from jockri/fix-formpage-submissions
Browse files Browse the repository at this point in the history
[FormBundle] Fix the formpage submissions due to the refactoring of the service method.
  • Loading branch information
Roderik van der Veer committed Apr 16, 2015
2 parents 034c8ea + 2405ccc commit ab4bb35
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 45 deletions.
49 changes: 21 additions & 28 deletions src/Kunstmaan/FormBundle/Controller/AbstractFormPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,39 @@

namespace Kunstmaan\FormBundle\Controller;


use Kunstmaan\NodeBundle\Helper\RenderContext;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;

/**
* Class AbstractFormPageController
* @package Kunstmaan\FormBundle\Controller
*/
class AbstractFormPageController extends Controller{

use Symfony\Component\HttpFoundation\Response;

class AbstractFormPageController extends Controller
{
/**
* @param Request $request
* @return null
*/
public function serviceAction(Request $request){

$context = array();
public function serviceAction(Request $request)
{
$thanksParam = $request->get('thanks');
if (!empty($thanksParam)) {
$context["thanks"] = true;

return null;
}
$entity = $request->attributes->get('_entity');

$renderContext = new RenderContext(
array(
'nodetranslation' => $request->attributes->get('_nodeTranslation'),
'slug' => $request->attributes->get('url'),
'page' => $entity,
'resource' => $entity,
'nodemenu' => $request->attributes->get('_nodeMenu'),
)
$context = array(
'nodetranslation' => $request->attributes->get('_nodeTranslation'),
'slug' => $request->attributes->get('url'),
'page' => $entity,
'resource' => $entity,
'nodemenu' => $request->attributes->get('_nodeMenu'),
);

$this->container->get('kunstmaan_form.form_handler')->handleForm($entity, $request, $renderContext);
if (!empty($thanksParam)) {
$context['thanks'] = true;
}

$renderContext = new RenderContext($context);
$result = $this->container->get('kunstmaan_form.form_handler')->handleForm($entity, $request, $renderContext);
if ($result instanceof Response) {
return $result;
}

$request->attributes->set('_renderContext', $renderContext->getArrayCopy());
}
}
}
27 changes: 10 additions & 17 deletions src/Kunstmaan/NodeBundle/EventListener/RenderContextListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,17 @@

namespace Kunstmaan\NodeBundle\EventListener;


use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\Templating\EngineInterface;

/**
* Class RenderContextListener
* @package Kunstmaan\NodeBundle\EventListener
*/
class RenderContextListener
{




/**
* @var EngineInterface
*/
protected $templating;

/**
* @param EntityManager $em
* @param EngineInterface $templating
*/
public function __construct(EngineInterface $templating)
Expand All @@ -39,8 +28,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
$request = $event->getRequest();
$nodeTranslation = $request->attributes->get('_nodeTranslation');

if($nodeTranslation) {
//fetch parameters;
if ($nodeTranslation) {
$entity = $request->attributes->get('_entity');
$url = $request->attributes->get('url');
$nodeMenu = $request->attributes->get('_nodeMenu');
Expand All @@ -51,11 +39,16 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
'page' => $entity,
'resource' => $entity,
'nodemenu' => $nodeMenu,
);
);

if (is_array($parameters)) {
$parameters = array_merge($renderContext, $parameters);
} else {
$parameters = $renderContext;
}

$parameters = array_merge($renderContext, $parameters);
//sent the response here, another option is to let the symfony kernel.view listener handle it
// Sent the response here, another option is to let the symfony kernel.view listener handle it
$event->setResponse($this->templating->renderResponse($entity->getDefaultView(), $parameters));
}
}
}
}

0 comments on commit ab4bb35

Please sign in to comment.