/**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     foreach ($view['locale']->vars['choices'] as $choice) {
         $choice->label = $this->localeHelper->getLocaleLabel($choice->label);
     }
     $view->vars['groups'] = $this->productFormView->getView();
 }
 /**
  * Method called before set data
  *
  * Change the code to a localized label
  *
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     $data = $event->getData();
     if (null === $data) {
         return;
     }
     $data->setCode($this->localeHelper->getLocaleLabel($data->getCode()));
 }
 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     $channels = $this->completenessRepo->getProductsCountPerChannels();
     $completeProducts = $this->completenessRepo->getCompleteProductsCountPerChannels();
     $data = [];
     foreach ($channels as $channel) {
         $data[$channel['label']] = ['total' => (int) $channel['total'], 'complete' => 0];
     }
     foreach ($completeProducts as $completeProduct) {
         $localeLabel = $this->localeHelper->getLocaleLabel($completeProduct['locale']);
         $data[$completeProduct['label']]['locales'][$localeLabel] = (int) $completeProduct['total'];
         $data[$completeProduct['label']]['complete'] += $completeProduct['total'];
     }
     return $data;
 }
 /**
  * On pre set data event
  * Build the custom form based on the provided locales
  *
  * @param FormEvent $event
  *
  * @return
  */
 public function preSetData(FormEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data) {
         return;
     }
     $translations = $this->bindTranslations($data);
     foreach ($translations as $binded) {
         $method = 'get' . Inflector::camelize($this->getOption('field'));
         $content = $binded['translation']->{$method}();
         $form->add($this->formFactory->createNamed($binded['fieldName'], $this->getOption('widget'), $content !== null ? $content : '', array('label' => $this->localeHelper->getLocaleLabel($binded['locale']), 'required' => in_array($binded['locale'], $this->getOption('required_locale')), 'mapped' => false, 'auto_initialize' => false)));
     }
 }
 /**
  * {@inheritdoc}
  *
  * Translate the locale codes to labels in the current user locale
  * and sort them alphabetically
  *
  * This part is done here because of the choices query is executed just before
  * so we can't access to these properties from form events
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     if (!isset($view['locales'])) {
         return;
     }
     /** @var array<ChoiceView> $locales */
     $locales = $view['locales'];
     foreach ($locales->vars['choices'] as $locale) {
         $locale->label = $this->localeHelper->getLocaleLabel($locale->label);
     }
     foreach ($locales->vars['preferred_choices'] as $locale) {
         $locale->label = $this->localeHelper->getLocaleLabel($locale->label);
     }
     $locales->vars['choices'] = SortHelper::sortByProperty($locales->vars['choices'], 'label');
     $locales->vars['preferred_choices'] = SortHelper::sortByProperty($locales->vars['preferred_choices'], 'label');
 }
 /**
  * Returns the flag icon for a locale with its country as long label or short code
  *
  * @param Twig_Environment $environment
  * @param string           $code
  * @param boolean          $short
  * @param string           $translateIn
  *
  * @return string
  */
 public function flag(Twig_Environment $environment, $code, $short = true, $translateIn = null)
 {
     return $environment->render('PimEnrichBundle:Locale:_flag.html.twig', ['label' => $this->localeHelper->getLocaleLabel($code, $translateIn), 'region' => $this->localeHelper->getRegion($code), 'language' => $this->localeHelper->getLanguage($code), 'short' => $short]);
 }