예제 #1
0
 /**
  * @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();
         }
     }
 }
예제 #2
0
 /**
  * @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'));
 }
예제 #3
0
 /**
  * {@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;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function getFallbackLocale()
 {
     if (!$this->parameterResolver->resolveApi()) {
         return $this->localeProvider->getDefaultLocale()->getCode();
     }
 }
예제 #5
0
 /**
  * {@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);
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultLocale()
 {
     return $this->localeProvider->getDefaultLocale()->getCode();
 }