Skip to content

Commit

Permalink
[CoreBundle] allow to pass site to link generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Dec 31, 2024
1 parent f045d50 commit c9ed368
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

use CoreShop\Component\Pimcore\DataObject\AbstractSluggableLinkGenerator;
use CoreShop\Component\Pimcore\DataObject\InheritanceHelper;
use Pimcore\Model\DataObject\Concrete;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Webmozart\Assert\Assert;

class DataObjectLinkGenerator extends AbstractSluggableLinkGenerator
{
Expand All @@ -33,6 +35,8 @@ public function __construct(

public function generate(object $object, array $params = []): string
{
Assert::isInstanceOf($object, Concrete::class);

$locale = $params['_locale'] ?? null;

$name = InheritanceHelper::useInheritedValues(function () use ($object, $locale) {
Expand All @@ -56,6 +60,10 @@ public function generate(object $object, array $params = []): string
$params['referenceType'] = UrlGeneratorInterface::ABSOLUTE_PATH;
}

if (isset($params['site'])) {
$routeParams['site'] = $params['site'];
}

return $this->urlGenerator->generate($params['route'] ?? $this->routeName, $routeParams, $params['referenceType']);
}
}

0 comments on commit c9ed368

Please sign in to comment.