/** * @param string $code * * @return LocaleInterface */ protected function getLocale($code) { if (!array_key_exists($code, $this->locales)) { $this->locales[$code] = $this->localeRepository->findOneByIdentifier($code); } return $this->locales[$code]; }
function let(TokenStorageInterface $tokenStorage, LocaleRepositoryInterface $localeRepository, ChannelRepositoryInterface $channelRepository, TokenInterface $token, User $user, LocaleInterface $en, LocaleInterface $fr, LocaleInterface $de, ChannelInterface $ecommerce, ChannelInterface $mobile, CategoryInterface $firstTree, CategoryInterface $secondTree, CategoryRepositoryInterface $productCategoryRepo, RequestStack $requestStack, ChoicesBuilderInterface $choicesBuilder) { $tokenStorage->getToken()->willReturn($token); $token->getUser()->willReturn($user); $en->getCode()->willReturn('en_US'); $fr->getCode()->willReturn('fr_FR'); $de->getCode()->willReturn('de_DE'); $en->isActivated()->willReturn(true); $fr->isActivated()->willReturn(true); $de->isActivated()->willReturn(true); $localeRepository->findOneByIdentifier('en_US')->willReturn($en); $localeRepository->findOneByIdentifier('fr_FR')->willReturn($fr); $localeRepository->findOneByIdentifier('de_DE')->willReturn($de); $localeRepository->getActivatedLocales()->willReturn([$en, $fr, $de]); $channelRepository->findOneBy([])->willReturn($mobile); $productCategoryRepo->getTrees()->willReturn([$firstTree, $secondTree]); $this->beConstructedWith($tokenStorage, $localeRepository, $channelRepository, $productCategoryRepo, $requestStack, $choicesBuilder, 'en_US'); }
/** * Check the consistency of the field with channel associated * * @param AttributeInterface $attribute * @param string $fieldName * @param array $attributeInfo * * @throws \InvalidArgumentException */ protected function checkFieldNameLocaleByChannel(AttributeInterface $attribute, $fieldName, array $attributeInfo) { if ($attribute->isScopable() && $attribute->isLocalizable() && isset($attributeInfo['scope_code']) && isset($attributeInfo['locale_code'])) { $channel = $this->channelRepository->findOneByIdentifier($attributeInfo['scope_code']); $locale = $this->localeRepository->findOneByIdentifier($attributeInfo['locale_code']); if ($channel !== null && $locale !== null && !$channel->hasLocale($locale)) { throw new \InvalidArgumentException(sprintf('The locale "%s" of the field "%s" is not available in scope "%s"', $attributeInfo['locale_code'], $fieldName, $attributeInfo['scope_code'])); } } }
/** * @param AttributeInterface $attribute * @param array $data */ protected function setAvailableLocales(AttributeInterface $attribute, array $data) { $localeSpecificCodes = $attribute->getLocaleSpecificCodes(); foreach ($data as $localeCode) { if (!in_array($localeCode, $localeSpecificCodes)) { $locale = $this->localeRepository->findOneByIdentifier($localeCode); $attribute->addAvailableLocale($locale); } } }
/** * @param AttributeInterface $attribute * @param string $field * @param array $availableLocaleCodes */ protected function setAvailableLocales(AttributeInterface $attribute, $field, array $availableLocaleCodes) { $locales = []; foreach ($availableLocaleCodes as $localeCode) { $locale = $this->localeRepository->findOneByIdentifier($localeCode); if (null !== $locale) { $locales[] = $locale; } } $this->accessor->setValue($attribute, $field, $locales); }
/** * @param string $code * @param bool $activeOnly * * @throws ObjectNotFoundException * * @return LocaleInterface */ protected function getLocale($code, $activeOnly = true) { if (!array_key_exists($code, $this->locales)) { $locale = $this->localeRepository->findOneByIdentifier($code); if (!$locale) { throw new ObjectNotFoundException(sprintf('Locale with code "%s" was not found.', $code)); } if ($activeOnly && !$locale->isActivated()) { throw new ObjectNotFoundException(sprintf('Active locale with code "%s" was not found.', $code)); } $this->locales[$code] = $locale; } return $this->locales[$code]; }
/** * Returns the default application locale * * @return LocaleInterface|null */ protected function getDefaultLocale() { return $this->localeRepository->findOneByIdentifier($this->defaultLocale); }