Skip to content

Commit

Permalink
Merge pull request #2260 from breakone/3.0
Browse files Browse the repository at this point in the history
[Pimcore] add locale to SlugGenerationEvent
  • Loading branch information
dpfaffenbauer committed Apr 26, 2023
2 parents c38d255 + 61215b5 commit c14622c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/CoreShop/Component/Pimcore/Event/SlugGenerationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(
protected string $slug,
protected ?string $suffix = null,
protected ?Site $site = null,
protected ?string $locale = null,
) {
}

Expand Down Expand Up @@ -56,4 +57,9 @@ public function getSite(): ?Site
{
return $this->site;
}

public function getLocale(): ?string
{
return $this->locale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
public function generateSlugsForSite(SluggableInterface $sluggable, string $locale, ?Site $site = null): string
{
$slug = $this->slugger->slug($sluggable, $locale, null);
$slug = $this->dispatchSlugEvent($sluggable, $slug, null, $site);
$slug = $this->dispatchSlugEvent($sluggable, $slug, null, $site, $locale);

$i = 1;

Expand All @@ -47,17 +47,17 @@ public function generateSlugsForSite(SluggableInterface $sluggable, string $loca
}

$slug = $this->slugger->slug($sluggable, $locale, (string) $i);
$slug = $this->dispatchSlugEvent($sluggable, $slug, (string) $i, $site);
$slug = $this->dispatchSlugEvent($sluggable, $slug, (string) $i, $site, $locale);

++$i;
}

return $slug;
}

private function dispatchSlugEvent(SluggableInterface $sluggable, string $slug, string $prefix = null, ?Site $site = null)
private function dispatchSlugEvent(SluggableInterface $sluggable, string $slug, string $prefix = null, ?Site $site = null, ?string $locale = null)
{
$event = new SlugGenerationEvent($sluggable, $slug, $prefix, $site);
$event = new SlugGenerationEvent($sluggable, $slug, $prefix, $site, $locale);
$this->eventDispatcher->dispatch($event);

return $event->getSlug();
Expand Down

0 comments on commit c14622c

Please sign in to comment.