/**
  * 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]);
     return new JsonResponse(['date' => ['format' => $dateFormatter->getPattern(), 'defaultFormat' => LocalizerInterface::DEFAULT_DATE_FORMAT], 'time' => ['format' => $timeFormatter->getPattern(), 'defaultFormat' => LocalizerInterface::DEFAULT_DATETIME_FORMAT], 'language' => $locale, '12_hour_format' => false !== strpos($timeFormatter->getPattern(), 'a')]);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $options = ['locale' => $this->localeResolver->getCurrentLocale()];
     $decimalSeparator = $this->numberFactory->create($options)->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
     $constraint = new NumberFormat();
     $constraint->decimalSeparator = $decimalSeparator;
     $message = $this->formatValidator->getMessage($constraint);
     $resolver->setDefaults(['decimals_allowed' => true, 'invalid_message' => $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;
 }
 /**
  * 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;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $placeholderDefault = function (Options $options) {
         return $options['required'] ? null : '';
     };
     $constraint = new DateFormat();
     $dateFormat = $this->dateFactory->create(['locale' => $this->localeResolver->getCurrentLocale()])->getPattern();
     $resolver->setDefaults(['widget' => 'single_text', 'placeholder' => 'oro.form.click_here_to_select', 'invalid_message' => $constraint->message, 'invalid_message_parameters' => ['{{ date_format }}' => $dateFormat], 'format' => $dateFormat])->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];
     });
 }
 /**
  * Present a date
  *
  * @param string $date
  *
  * @return string
  */
 public function datePresenter($date)
 {
     return $this->datePresenter->present($date, ['locale' => $this->localeResolver->getCurrentLocale()]);
 }