/**
  * @return Item
  */
 private function createRootItem()
 {
     $translation = new Item('translation-locale');
     $translation->setLabel($this->translator->trans('admin.locale.dropdown.title', array('%locale%' => $this->localeManager->getLocale()), 'FSiAdminTranslatableBundle'));
     $translation->setOptions(array('attr' => array('id' => 'translatable-switcher')));
     return $translation;
 }
예제 #2
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;
 }
 /**
  * {@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 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);
 }
 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);
 }
 /**
  * {@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;
 }