/** * @param LocaleInterface $locale * @param LocaleIntegrity $constraint */ private function validateDefaultLocale(LocaleInterface $locale, LocaleIntegrity $constraint) { if ($this->localeProvider->getDefaultLocale() === $locale) { if (!$locale->isEnabled()) { $this->context->buildViolation($constraint->defaultEnabledMessage)->atPath('enabled')->addViolation(); } if (!$locale->isRequired()) { $this->context->buildViolation($constraint->defaultRequiredMessage)->atPath('required')->addViolation(); } } }
/** * @param DomainEvent $event */ public function validateDefaultLocale(DomainEvent $event) { $data = $event->getData(); if ($data !== $this->localeProvider->getDefaultLocale()) { return; } $resource = $event->getResource(); $event->setStopped(true); $event->setStatusCode(409); $event->setMessageType('error'); $event->setMessage($this->translator->trans('lug.' . $resource->getName() . '.' . $event->getAction() . '.default', ['%' . $resource->getName() . '%' => $this->propertyAccessor->getValue($data, $resource->getLabelPropertyPath())], 'flashes')); }
/** * {@inheritdoc} */ public function getLocales() { if (($request = $this->requestStack->getMasterRequest()) === null) { return [$this->localeProvider->getDefaultLocale()->getCode()]; } $locales = []; if ($this->parameterResolver->resolveApi()) { $locales = $this->parseAcceptLanguage($request); } if (empty($locales)) { $locales = [$request->getLocale()]; } return $locales; }
/** * {@inheritdoc} */ public function getFallbackLocale() { if (!$this->parameterResolver->resolveApi()) { return $this->localeProvider->getDefaultLocale()->getCode(); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $childOptions = ['disabled' => $builder->getData() === $this->localeProvider->getDefaultLocale()]; $builder->add('code', LocaleCodeType::class, $childOptions)->add('enabled', CheckboxType::class, array_merge(['invalid_message' => 'lug.locale.enabled.invalid'], $childOptions))->add('required', CheckboxType::class, array_merge(['invalid_message' => 'lug.locale.required.invalid'], $childOptions))->add('submit', SubmitType::class); }
/** * {@inheritdoc} */ public function getDefaultLocale() { return $this->localeProvider->getDefaultLocale()->getCode(); }