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

[FormBundle] Fix the formpage submissions due to the refactoring of the service method. #342

Merged
merged 1 commit into from
Apr 16, 2015
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
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));
}
}
}
}