예제 #1
0
 /**
  * @param array $actionValues
  * @param \FSi\Bundle\AdminTranslatableBundle\Manager\LocaleManager $localeManager
  * @return mixed
  */
 private function setRouteLocale($actionValues, $localeManager)
 {
     if (in_array('locale', $this->getRouteVariables($actionValues['route_name']))) {
         $actionValues['additional_parameters']['locale'] = $localeManager->getLocale();
     }
     return $actionValues;
 }
 function it_sets_locale_to_locale_manager(GetResponseEvent $event, Request $request, LocaleManager $localeManager)
 {
     $event->getRequest()->willReturn($request);
     $request->get('locale')->willReturn('pl');
     $localeManager->setLocale('pl')->shouldBeCalled();
     $this->onKernelRequest($event);
 }
 function it_should_correctly_match_the_same_elements_with_different_locale(VoterInterface $menuElementVoter, ItemInterface $item, LocaleManager $localeManager)
 {
     $localeManager->getLocale()->willReturn('pl');
     $menuElementVoter->matchItem($item)->willReturn(true);
     $item->getExtra('routes', array())->willReturn(array(0 => array('parameters' => array('locale' => 'en'))));
     $this->matchItem($item)->shouldReturn(false);
     $item->getExtra('routes', array())->willReturn(array(0 => array('parameters' => array('locale' => 'pl'))));
     $this->matchItem($item)->shouldReturn(true);
     $item->getExtra('routes', array())->willReturn(array(0 => array('parameters' => array('locale' => 'de'))));
     $this->matchItem($item)->shouldReturn(false);
 }
 /**
  * {@inheritdoc}
  */
 public function matchItem(ItemInterface $item)
 {
     $elementMatch = $this->menuElementVoter->matchItem($item);
     if (false === $elementMatch || null === $elementMatch) {
         return $elementMatch;
     }
     $currentLocale = $this->localeManager->getLocale();
     $routes = (array) $item->getExtra('routes', array());
     foreach ($routes as $testedRoute) {
         $routeParameters = $testedRoute['parameters'];
         if (!isset($routeParameters['locale'])) {
             continue;
         }
         return $routeParameters['locale'] === $currentLocale;
     }
     return $elementMatch;
 }
 function let(TranslatorInterface $translator, Router $router, LocaleManager $localeManager, RequestStack $requestStack, Request $request, ParameterBag $query, ParameterBag $server)
 {
     $localeManager->getLocale()->willReturn('en');
     $request->getLocale()->willReturn('en');
     $request->get('_route_params')->willReturn(array('element' => 'event', 'locale' => 'en'));
     $request->get('_route')->willReturn('admin_translatable_list');
     $requestStack->getCurrentRequest()->willReturn($request);
     $query->all()->willReturn(array('param1' => 'val1', 'redirect_uri' => '/admin/en/list/element?param=value'));
     $request->query = $query;
     $router->matchRequest(Argument::that(function ($argument) {
         return $argument->server->get('REQUEST_URI') === '/admin/en/list/element' && $argument->server->get('QUERY_STRING') === 'param=value';
     }))->willReturn(array('_route' => 'some_admin_route', 'locale' => 'en', 'element' => 'element'));
     $request->server = $server;
     $localeManager->getLocales()->willReturn(array('pl', 'en', 'de'));
     $translator->trans('admin.locale.dropdown.title', array('%locale%' => 'en'), 'FSiAdminTranslatableBundle')->willReturn('Menu label');
     $this->beConstructedWith($translator, $router, $localeManager, $requestStack);
 }
 private function populateTranslationLocaleMenu(Item $menu)
 {
     $requestParameters = $this->getRequestParameters();
     $route = $this->request->get('_route');
     $languageBundle = Intl::getLanguageBundle();
     if (isset($requestParameters['redirect_uri'])) {
         $redirectRequest = $this->createRedirectRequest($requestParameters['redirect_uri']);
     }
     foreach ($this->localeManager->getLocales() as $locale) {
         $requestParameters['locale'] = $locale;
         if (isset($redirectRequest)) {
             try {
                 $requestParameters['redirect_uri'] = $this->generateRequestUriForLocale($redirectRequest, $locale);
             } catch (ResourceNotFoundException $e) {
             }
         }
         $localeItem = new RoutableItem(sprintf('translation-locale.%s', $locale), $route, $requestParameters);
         $localeItem->setLabel($languageBundle->getLanguageName($locale, null, $this->request->getLocale()));
         $menu->addChild($localeItem);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     $data = parent::getData();
     $data['translatable_locale'] = $this->localeManager->getLocale();
     return $data;
 }
 protected function appendLocaleParameter(array $parameters)
 {
     $parameters['locale'] = $this->localeManager->getLocale();
     return $parameters;
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if ($locale = $event->getRequest()->get('locale')) {
         $this->localeManager->setLocale($locale);
     }
 }