Skip to content

Commit

Permalink
inject current locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste authored and Leny Bernard committed Apr 19, 2019
1 parent a1ac439 commit c33c2d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Resolver/WidgetRenderContentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace Victoire\Widget\RenderBundle\Resolver;

use Symfony\Component\HttpFoundation\RequestStack;
use Victoire\Bundle\WidgetBundle\Model\Widget;
use Victoire\Bundle\WidgetBundle\Resolver\BaseWidgetContentResolver;

class WidgetRenderContentResolver extends BaseWidgetContentResolver
{
/** @var RequestStack */
private $requestStack;

/**
* Get the business entity content.
*
Expand Down Expand Up @@ -68,4 +72,26 @@ public function readIntoWidgetRouteParameters(Widget $widget)
}
$widget->setParams($params);
}

/**
* Get the static content of the widget.
*
* @param Widget $widget
* @return array
*/
public function getWidgetStaticContent(Widget $widget)
{
$parameters = parent::getWidgetStaticContent($widget);
$curentRequest = $this->requestStack->getCurrentRequest();

return array_merge($parameters, $curentRequest->request->all(), ['_locale' => $curentRequest->getLocale()]);
}

/**
* @param RequestStack $requestStack
*/
public function setRequestStack(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
}
2 changes: 2 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
parent: victoire_widget.base_widget_content_resolver
tags:
- { name: victoire_widget.widget_content_resolver, alias: Render }
calls:
- [setRequestStack, ["@request_stack"]]
#alias to the entity
victoire.widget.render:
class: Victoire\Widget\RenderBundle\Entity\WidgetRender
Expand Down

0 comments on commit c33c2d3

Please sign in to comment.