/**
  * Date format action (show pattern expected for current locale)
  *
  * @return JsonResponse
  */
 public function dateAction()
 {
     $locale = $this->localeResolver->getCurrentLocale();
     $dateFormatter = $this->dateFactory->create(['locale' => $locale]);
     $timeFormatter = $this->datetimeFactory->create(['locale' => $locale, 'timetype' => \IntlDateFormatter::SHORT]);
     return new JsonResponse(['date' => ['format' => $dateFormatter->getPattern(), 'defaultFormat' => LocalizerInterface::DEFAULT_DATE_FORMAT], 'time' => ['format' => $timeFormatter->getPattern(), 'defaultFormat' => LocalizerInterface::DEFAULT_DATETIME_FORMAT], 'language' => $locale]);
 }
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $options = ['locale' => $this->localeResolver->getCurrentLocale()];
     $decimalSeparator = $this->localeResolver->getFormats()['decimal_separator'];
     $constraint = new NumberFormat();
     $resolver->setDefaults(['decimals_allowed' => true, 'invalid_message' => $constraint->message, 'invalid_message_parameters' => ['{{ decimal_separator }}' => $decimalSeparator], 'locale_options' => $options]);
 }
 /**
  * {@inheritdoc}
  */
 public function normalize($comment, $format = null, array $context = [])
 {
     if (!$this->serializer instanceof NormalizerInterface) {
         throw new \LogicException('Serializer must be a normalizer');
     }
     $context = ['locale' => $this->localeResolver->getCurrentLocale()];
     $data = ['id' => $comment->getId(), 'resourceName' => $comment->getResourceName(), 'resourceId' => $comment->getResourceId(), 'author' => ['username' => $comment->getAuthor()->getUsername(), 'fullName' => $comment->getAuthor()->getFirstName() . ' ' . $comment->getAuthor()->getLastName()], 'body' => $comment->getBody(), 'created' => $this->datetimePresenter->present($comment->getCreatedAt(), $context), 'replied' => $this->datetimePresenter->present($comment->getRepliedAt(), $context), 'replies' => $this->serializer->normalize($comment->getChildren(), 'json')];
     return $data;
 }
 /**
  * @param FormEvent $event
  */
 public function postSubmit(FormEvent $event)
 {
     $data = $event->getData();
     if (null === $data || !$data instanceof ProductTemplateInterface) {
         return;
     }
     $options = ['entity' => 'product', 'locale' => $this->localeResolver->getCurrentLocale(), 'disable_grouping_separator' => true];
     $valuesData = $this->normalizer->normalize($data->getValues(), 'json', $options);
     $data->setValuesData($valuesData);
 }
 /**
  * Presents an attribute option
  *
  * @param string $value
  * @param string $optionName
  *
  * @return string|null
  */
 public function attributeOptionPresenter($value, $optionName)
 {
     $presenter = $this->presenterRegistry->getAttributeOptionPresenter($optionName);
     if (null !== $presenter) {
         $locale = $this->localeResolver->getCurrentLocale();
         if (null !== $locale) {
             return $presenter->present($value, ['locale' => $locale]);
         }
     }
     return $value;
 }
 /**
  * Localize the changeset values
  *
  * @param array $changeset
  *
  * @return array
  */
 protected function convertChangeset(array $changeset)
 {
     $formats = $this->localeResolver->getFormats();
     foreach ($changeset as $attribute => $changes) {
         $attributeName = $attribute;
         if (preg_match('/^(?<attribute>[a-zA-Z0-9_]+)-.+$/', $attribute, $matches)) {
             $attributeName = $matches['attribute'];
         }
         foreach ($changes as $key => $value) {
             $changeset[$attribute][$key] = $this->converter->convertDefaultToLocalizedValue($attributeName, $value, $formats);
         }
     }
     return $changeset;
 }
 /**
  * Build product values from template values raw data
  *
  * @param ProductTemplateInterface $template
  * @param AttributeInterface[]     $attributes
  *
  * @return ProductValueInterface[]
  */
 protected function buildProductValuesFromTemplateValuesData(ProductTemplateInterface $template, array $attributes)
 {
     $options = ['locale' => $this->localeResolver->getCurrentLocale(), 'disable_grouping_separator' => true];
     $values = $this->denormalizer->denormalize($template->getValuesData(), 'ProductValue[]', 'json', $options);
     $product = new $this->productClass();
     foreach ($values as $value) {
         $product->addValue($value);
     }
     foreach ($attributes as $attribute) {
         $this->productBuilder->addAttributeToProduct($product, $attribute);
     }
     $this->productBuilder->addMissingProductValues($product);
     return $product->getValues();
 }
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $placeholderDefault = function (Options $options) {
         return $options['required'] ? null : '';
     };
     $constraint = new DateFormat();
     $localeOptions = $this->localeResolver->getFormats();
     $resolver->setDefaults(['widget' => 'single_text', 'placeholder' => 'oro.form.click_here_to_select', 'invalid_message' => $constraint->message, 'invalid_message_parameters' => ['{{ date_format }}' => $localeOptions['date_format']], 'locale_options' => $localeOptions, 'format' => $localeOptions['date_format']])->setNormalizer('placeholder', function (Options $options, $placeholder) use($placeholderDefault) {
         if (is_string($placeholder)) {
             return $placeholder;
         } elseif (is_array($placeholder)) {
             $default = $placeholderDefault($options);
             return array_merge(['year' => $default, 'month' => $default, 'day' => $default], $placeholder);
         }
         return ['year' => $placeholder, 'month' => $placeholder, 'day' => $placeholder];
     });
 }
 /**
  * Localize the changeset values
  *
  * @param array $changeset
  *
  * @return array
  */
 protected function convertChangeset(array $changeset)
 {
     $options = ['locale' => $this->localeResolver->getCurrentLocale()];
     foreach ($changeset as $attribute => $changes) {
         $options['versioned_attribute'] = $attribute;
         $attributeName = $attribute;
         if (preg_match('/^(?<attribute>[a-zA-Z0-9_]+)-.+$/', $attribute, $matches)) {
             $attributeName = $matches['attribute'];
         }
         $presenter = $this->presenterRegistry->getPresenterByAttributeCode($attributeName);
         if (null !== $presenter) {
             foreach ($changes as $key => $value) {
                 $changeset[$attribute][$key] = $presenter->present($value, $options);
             }
         }
     }
     return $changeset;
 }
 /**
  * Present a date
  *
  * @param string $date
  *
  * @return string
  */
 public function datePresenter($date)
 {
     return $this->datePresenter->present($date, ['locale' => $this->localeResolver->getCurrentLocale()]);
 }