Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pimcore] add locale to SlugGenerationEvent #2260

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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