public function createAccountMenu(MenuEvent $event)
 {
     $rootItem = $this->createRootItem();
     $changePasswordItem = new RoutableItem('account.change-password', 'fsi_admin_change_password');
     $changePasswordItem->setLabel($this->translator->trans('admin.change_password', array(), 'FSiAdminSecurity'));
     $rootItem->addChild($changePasswordItem);
     $logoutItem = new RoutableItem('account.logout', 'fsi_admin_security_user_logout');
     $logoutItem->setLabel($this->translator->trans('admin.logout', array(), 'FSiAdminSecurity'));
     $rootItem->addChild($logoutItem);
     $event->getMenu()->addChild($rootItem);
     return $event->getMenu();
 }
Ejemplo n.º 2
0
 public function createLocaleMenu(MenuEvent $event)
 {
     if (count($this->locales) < 2) {
         return;
     }
     $language = new Item('admin-locale');
     $language->setLabel($this->translator->trans('admin.language.current', array('%locale%' => $this->getLanguageName()), 'FSiAdminBundle'));
     $language->setOptions(array('attr' => array('id' => 'language')));
     foreach ($this->locales as $locale) {
         $localeItem = new RoutableItem(sprintf('admin-locale.%s', $locale), 'fsi_admin_locale', array('_locale' => $locale, 'redirect_uri' => $this->requestStack->getMasterRequest()->getUri()));
         $localeItem->setLabel($this->getLanguageName($locale));
         if ($locale === $this->getCurrentLocale()) {
             $localeItem->setOptions(array('attr' => array('class' => 'active')));
         }
         $language->addChild($localeItem);
     }
     $event->getMenu()->addChild($language);
 }
 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);
     }
 }
Ejemplo n.º 4
0
 protected function configureOptions(OptionsResolver $optionsResolver)
 {
     parent::configureOptions($optionsResolver);
     $optionsResolver->setDefaults(array('elements' => array()));
     $optionsResolver->setAllowedTypes('elements', array('array'));
     $optionsResolver->setNormalizer('elements', function (Options $options, array $value) {
         foreach ($value as $element) {
             if (!$element instanceof Element) {
                 throw new InvalidOptionsException(sprintf('Instance of FSi\\Bundle\\AdminBundle\\Admin\\Element expected but got %s', is_object($element) ? get_class($element) : gettype($element)));
             }
         }
         return $value;
     });
 }