src/EventSubscriber/Taxonomy/TaxonResourceSubscriber.php line 31
<?phpnamespace App\EventSubscriber\Taxonomy;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\EventDispatcher\GenericEvent;use Webmozart\Assert\Assert;use Sylius\Component\Customer\Model\CustomerInterface;use App\Repository\Customer\CustomerRepository;use App\Entity\Channel\ChannelEcodaAccountInfo;use App\Repository\Channel\ChannelEcodaAccountInfoRepository;use App\Repository\Channel\ChannelEcodaAccountTypeRepository;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;use App\Manager\EcodaAccountManager;use App\Entity\Taxon\TaxonVariant;use App\Entity\Taxonomy\Taxon;use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;class TaxonResourceSubscriber implements EventSubscriberInterface{private $taxonRepository;public function __construct(RequestStack $request, TaxonRepositoryInterface $taxonRepository){$this->taxonRepository = $taxonRepository;}public function onPreCreate(GenericEvent $event){$entity = $event->getSubject();Assert::isInstanceOf($entity, Taxon::class);$code = null;$words = explode(' ',$entity->getName());foreach ($words as $word) {$code = $code.substr($word, 0, 1);}$i = 1;while ($this->taxonRepository->findOneBy(['code'=> strtolower($code.'-'.$i)])) {$i++;}$code = strtolower($code.'-'.$i);$entity->setCode($code);}public static function getSubscribedEvents(){return ['sylius.taxon.pre_create' => 'onPreCreate',];}}