/** * {@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]); }
/** * 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; }
/** * {@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]; }); }