1313use Sylius \Component \Locale \Model \LocaleInterface ;
1414use Sylius \Component \Resource \Factory \FactoryInterface ;
1515use Sylius \Component \Resource \Repository \RepositoryInterface ;
16+ use Sylius \Component \Taxonomy \Repository \TaxonRepositoryInterface ;
1617use Symfony \Component \Config \FileLocatorInterface ;
1718use Symfony \Component \HttpFoundation \File \UploadedFile ;
1819use Symfony \Component \OptionsResolver \Options ;
@@ -26,6 +27,9 @@ final class BannerExampleFactory extends AbstractExampleFactory
2627 /** @var ChannelRepositoryInterface */
2728 private $ channelRepository ;
2829
30+ /** @var TaxonRepositoryInterface */
31+ private $ taxonRepository ;
32+
2933 /** @var RepositoryInterface */
3034 private $ localeRepository ;
3135
@@ -41,11 +45,13 @@ final class BannerExampleFactory extends AbstractExampleFactory
4145 public function __construct (
4246 FactoryInterface $ bannerFactory ,
4347 ChannelRepositoryInterface $ channelRepository ,
48+ TaxonRepositoryInterface $ taxonRepository ,
4449 RepositoryInterface $ localeRepository ,
4550 ?FileLocatorInterface $ fileLocator = null
4651 ) {
4752 $ this ->bannerFactory = $ bannerFactory ;
4853 $ this ->channelRepository = $ channelRepository ;
54+ $ this ->taxonRepository = $ taxonRepository ;
4955 $ this ->localeRepository = $ localeRepository ;
5056 $ this ->fileLocator = $ fileLocator ;
5157
@@ -74,6 +80,10 @@ protected function configureOptions(OptionsResolver $resolver): void
7480 return __DIR__ .'/../../Resources/fixtures/banner/mobile-images/0 ' .rand (1 , 4 ).'.png ' ;
7581 })
7682 ->setAllowedTypes ('mobile_image ' , ['string ' ])
83+
84+ ->setDefault ('taxons ' , [])
85+ ->setAllowedTypes ('taxons ' , 'array ' )
86+ ->setNormalizer ('taxons ' , LazyOption::findBy ($ this ->taxonRepository , 'code ' ))
7787 ;
7888 }
7989
@@ -92,6 +102,10 @@ public function create(array $options = []): BannerInterface
92102 $ banner ->addChannel ($ channel );
93103 }
94104
105+ foreach ($ options ['taxons ' ] as $ taxon ) {
106+ $ banner ->addTaxon ($ taxon );
107+ }
108+
95109 /** @var string $localeCode */
96110 foreach ($ this ->getLocales () as $ localeCode ) {
97111 $ banner ->setCurrentLocale ($ localeCode );
0 commit comments