/**
  * {@inheritdoc}
  */
 public function findTranslatedLabels(array $options = [])
 {
     $query = $this->createQueryBuilder('f')->select('f.id')->addSelect('COALESCE(NULLIF(ft.label, \'\'), CONCAT(\'[\', f.code, \']\')) as label')->leftJoin('f.translations', 'ft', 'WITH', 'ft.locale = :locale_code')->orderBy('label')->setParameter('locale_code', $this->userContext->getCurrentLocaleCode())->getQuery();
     $choices = [];
     foreach ($query->getArrayResult() as $family) {
         $choices[$family['id']] = $family['label'];
     }
     return $choices;
 }
 /**
  * {@inheritdoc}
  */
 public function findTranslatedLabels(array $options = [])
 {
     $queryBuilder = $this->createQueryBuilder('g')->select('g.id')->addSelect('COALESCE(NULLIF(t.label, \'\'), CONCAT(\'[\', g.code, \']\')) as label')->leftJoin('g.translations', 't', 'WITH', 't.locale = :locale')->setParameter('locale', $this->userContext->getCurrentLocaleCode())->orderBy('t.label');
     if (isset($options['type'])) {
         $queryBuilder->andWhere('g.type = :type')->setParameter('type', $options['type']);
     }
     $choices = [];
     foreach ($queryBuilder->getQuery()->getArrayResult() as $code) {
         $choices[$code['id']] = $code['label'];
     }
     return $choices;
 }
 /**
  * Get datalocale from parent's parameters, fallback on request parameters to deal with the mass edit case
  *
  * @param array $queryParameters
  *
  * @return string
  */
 protected function getLocale($queryParameters)
 {
     $dataLocale = null;
     if (isset($queryParameters['dataLocale'])) {
         $dataLocale = $queryParameters['dataLocale'];
     }
     if (null === $dataLocale) {
         $dataLocale = $this->request->get('dataLocale', null);
     }
     if (null === $dataLocale) {
         $dataLocale = $this->userContext->getCurrentLocaleCode();
     }
     return $dataLocale;
 }
 /**
  * {@inheritdoc}
  */
 public function findTranslatedLabels(array $options = [])
 {
     $queryBuilder = $this->createQueryBuilder('a')->select('a.code')->addSelect('COALESCE(NULLIF(at.label, \'\'), CONCAT(\'[\', a.code, \']\')) as attribute_label')->addSelect('COALESCE(NULLIF(gt.label, \'\'), CONCAT(\'[\', g.code, \']\')) as group_label')->leftJoin('a.translations', 'at', 'WITH', 'at.locale = :locale_code')->leftJoin('a.group', 'g')->leftJoin('g.translations', 'gt', 'WITH', 'gt.locale = :locale_code')->orderBy('g.sortOrder, a.sortOrder')->setParameter('locale_code', $this->userContext->getCurrentLocaleCode());
     if (isset($options['excluded_attribute_ids']) && !empty($options['excluded_attribute_ids'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->notIn('a.id', $options['excluded_attribute_ids']));
     }
     if (isset($options['useable_as_grid_filter'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->eq('a.useableAsGridFilter', $options['useable_as_grid_filter']));
     }
     $choices = [];
     foreach ($queryBuilder->getQuery()->getArrayResult() as $attribute) {
         $choices[$attribute['group_label']][$attribute['code']] = $attribute['attribute_label'];
     }
     return $choices;
 }
 function let(UserContext $userContext, EntityManager $em, ClassMetadata $classMetadata)
 {
     $classMetadata->name = 'group_type';
     $userContext->getCurrentLocaleCode()->willReturn('en_US');
     $em->getClassMetadata('groupTypeClass')->willReturn($classMetadata);
     $this->beConstructedWith($userContext, $em, 'groupTypeClass');
 }
 function let(SecurityContextInterface $securityContext, AddLocaleListener $listener, CatalogContext $catalogContext, UserContext $userContext, GetResponseEvent $event)
 {
     $securityContext->getToken()->willReturn(true);
     $event->getRequestType()->willReturn(HttpKernel::MASTER_REQUEST);
     $userContext->getCurrentLocaleCode()->willReturn('de_DE');
     $userContext->getUserChannelCode()->willReturn('schmetterling');
     $this->beConstructedWith($securityContext, $listener, $catalogContext, $userContext);
 }
 function let(UserContext $userContext, EntityManager $em, ClassMetadata $classMetadata, EventManager $eventManager, TreeListener $treeListener, Nested $strategy)
 {
     $classMetadata->name = 'category';
     $userContext->getCurrentLocaleCode()->willReturn('en_US');
     $em->getEventManager()->willReturn($eventManager);
     $eventManager->getListeners()->willReturn([[$treeListener]]);
     $treeListener->getStrategy(Argument::cetera())->willReturn($strategy);
     $treeListener->getConfiguration(Argument::cetera())->willReturn(['parent' => 'parent', 'left' => 'left']);
     $this->beConstructedWith($userContext, $em, $classMetadata);
 }
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setRequired(array('class'));
     $resolver->setOptional(array('locale', 'url'));
     $resolver->setDefaults(array('multiple' => false, 'transformer_options' => array(), 'collection_id' => null, 'route' => 'pim_ui_ajaxentity_list', 'route_parameters' => array(), 'data_class' => null, 'error_bubbling' => false, 'minimum_input_length' => 0));
     $resolver->setNormalizers(array('locale' => function (Options $options, $value) {
         if (!$value) {
             $value = $this->userContext->getCurrentLocaleCode();
         }
         return $value;
     }, 'url' => function (Options $options, $value) {
         if (!$value) {
             $parameters = $this->getRouteParameters($options);
             $value = $this->router->generate($options['route'], $parameters);
         }
         return $value;
     }));
 }
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setRequired(['class']);
     $resolver->setDefined(['locale', 'url']);
     $resolver->setDefaults(['multiple' => false, 'transformer_options' => [], 'collection_id' => null, 'route' => 'pim_ui_ajaxentity_list', 'route_parameters' => [], 'data_class' => null, 'error_bubbling' => false, 'minimum_input_length' => 0, 'locale' => null, 'url' => null, 'is_creatable' => false]);
     $resolver->setNormalizer('locale', function (Options $options, $value) {
         if (!$value) {
             $value = $this->userContext->getCurrentLocaleCode();
         }
         return $value;
     })->setNormalizer('url', function (Options $options, $value) {
         if (!$value) {
             $parameters = $this->getRouteParameters($options);
             $value = $this->router->generate($options['route'], $parameters);
         }
         return $value;
     });
 }
 /**
  * Define locale and scope in CatalogContext
  */
 protected function configureCatalogContext()
 {
     $this->catalogContext->setLocaleCode($this->userContext->getCurrentLocaleCode());
     $this->catalogContext->setScopeCode($this->userContext->getUserChannelCode());
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('attributes', 'light_entity', ['repository' => $this->attributeRepository, 'repository_options' => ['excluded_attribute_ids' => $options['attributes'], 'locale_code' => $this->userContext->getCurrentLocaleCode()], 'multiple' => true, 'expanded' => false]);
 }
 /**
  * @return array
  */
 protected function getChoiceUrlParams()
 {
     return ['class' => $this->groupClass, 'dataLocale' => $this->userContext->getCurrentLocaleCode(), 'collectionId' => null];
 }
 /**
  * Get choices
  *
  * @return array
  */
 public function getChoices()
 {
     return $this->repository->getChoices(['localeCode' => $this->userContext->getCurrentLocaleCode()]);
 }
 /**
  * {@inheritdoc}
  */
 protected function getFormOptions()
 {
     return array_merge(parent::getFormOptions(), ['choice_url' => 'pim_ui_ajaxentity_list', 'choice_url_params' => ['class' => $this->groupClass, 'dataLocale' => $this->userContext->getCurrentLocaleCode(), 'collectionId' => null]]);
 }
 /**
  * @param AttributeInterface $attribute
  *
  * @return array
  */
 protected function getChoiceUrlParams(AttributeInterface $attribute)
 {
     return ['class' => $this->optionRepoClass, 'dataLocale' => $this->userContext->getCurrentLocaleCode(), 'collectionId' => $attribute->getId()];
 }
 /**
  * Get data locale code
  *
  * @throws \Exception
  *
  * @return string
  */
 protected function getDataLocaleCode()
 {
     return $this->userContext->getCurrentLocaleCode();
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 protected function getFormOptions()
 {
     $attribute = $this->getAttribute();
     return array_merge(parent::getFormOptions(), ['choice_url' => 'pim_ui_ajaxentity_list', 'choice_url_params' => ['class' => $this->optionRepoClass, 'dataLocale' => $this->userContext->getCurrentLocaleCode(), 'collectionId' => $attribute->getId()]]);
 }