Skip to content

Commit

Permalink
Add a slugger when creating terms
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Feb 16, 2024
1 parent 3126bb9 commit cf57877
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 53 deletions.
12 changes: 12 additions & 0 deletions src/DependencyInjection/SetonoSyliusTermsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,17 @@ public function prepend(ContainerBuilder $container): void
],
],
]);

$container->prependExtensionConfig('sylius_ui', [
'events' => [
'setono_sylius_terms.admin.terms.create.javascripts' => [
'blocks' => [
'javascripts' => [
'template' => '@SetonoSyliusTermsPlugin/Admin/Terms/_javascripts.html.twig',
],
],
],
],
]);
}
}
5 changes: 2 additions & 3 deletions src/Fixture/Factory/TermsExampleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use DateTimeInterface;
use Faker\Factory as FakerFactory;
use Faker\Generator as FakerGenerator;
use Setono\SyliusTermsPlugin\Generator\TermSlugGeneratorInterface;
use Setono\SyliusTermsPlugin\Model\TermsInterface;
use Setono\SyliusTermsPlugin\Repository\TermsRepositoryInterface;
use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory;
Expand All @@ -21,6 +20,7 @@
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\String\Slugger\AsciiSlugger;

class TermsExampleFactory extends AbstractExampleFactory
{
Expand All @@ -33,7 +33,6 @@ public function __construct(
private readonly TermsRepositoryInterface $termsRepository,
private readonly RepositoryInterface $localeRepository,
private readonly ChannelRepositoryInterface $channelRepository,
private readonly TermSlugGeneratorInterface $termsSlugGenerator,
) {
$this->faker = FakerFactory::create();
$this->optionsResolver = new OptionsResolver();
Expand Down Expand Up @@ -84,7 +83,7 @@ protected function createTranslation(TermsInterface $terms, string $localeCode,
$terms->setName($options['name']);
$terms->setLabel($options['label']);
$terms->setContent($options['content']);
$terms->setSlug($options['slug'] ?? $this->termsSlugGenerator->generate($terms, $localeCode));
$terms->setSlug($options['slug'] ?? (new AsciiSlugger())->slug($options['name'])->toString());
}

protected function configureOptions(OptionsResolver $resolver): void
Expand Down
21 changes: 0 additions & 21 deletions src/Generator/TermSlugGenerator.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Generator/TermSlugGeneratorInterface.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<import resource="services/event_subscriber.xml"/>
<import resource="services/fixture.xml"/>
<import resource="services/form.xml"/>
<import resource="services/generator.xml"/>
<import resource="services/provider.xml"/>
<import resource="services/renderer.xml"/>
</imports>
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services/fixture.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<argument type="service" id="setono_sylius_terms.repository.terms"/>
<argument type="service" id="sylius.repository.locale"/>
<argument type="service" id="sylius.repository.channel"/>
<argument type="service" id="setono_sylius_terms.generator.term_slug"/>
</service>

<service id="setono_sylius_terms.fixture.terms"
Expand Down
15 changes: 0 additions & 15 deletions src/Resources/config/services/generator.xml

This file was deleted.

Loading

0 comments on commit cf57877

Please sign in to comment.