6 declare(strict_types=1);
31 private $storeManager;
36 private $customUrlLocator;
48 $this->urlFinder = $urlFinder;
50 $this->customUrlLocator = $customUrlLocator;
63 if (!isset($args[
'url']) || empty(trim($args[
'url']))) {
69 if (substr(
$url, 0, 1) ===
'/' &&
$url !==
'/') {
72 $customUrl = $this->customUrlLocator->locateUrl(
$url);
74 $urlRewrite = $this->findCanonicalUrl(
$url);
77 'id' => $urlRewrite->getEntityId(),
78 'canonical_url' => $urlRewrite->getTargetPath(),
79 'type' => $this->sanitizeType($urlRewrite->getEntityType())
93 $urlRewrite = $this->findUrlFromRequestPath($requestPath);
94 if ($urlRewrite && $urlRewrite->getRedirectType() > 0) {
95 while ($urlRewrite && $urlRewrite->getRedirectType() > 0) {
96 $urlRewrite = $this->findUrlFromRequestPath($urlRewrite->getTargetPath());
100 $urlRewrite = $this->findUrlFromTargetPath($requestPath);
112 private function findUrlFromRequestPath(
string $requestPath) : ?\
Magento\UrlRewrite\Service\V1\Data\UrlRewrite
114 return $this->urlFinder->findOneByData(
116 'request_path' => $requestPath,
117 'store_id' => $this->storeManager->getStore()->getId()
128 private function findUrlFromTargetPath(
string $targetPath) : ?\
Magento\UrlRewrite\Service\V1\Data\UrlRewrite
130 return $this->urlFinder->findOneByData(
132 'target_path' => $targetPath,
133 'store_id' => $this->storeManager->getStore()->getId()
144 private function sanitizeType(
string $type) : string
146 return strtoupper(str_replace(
'-',
'_',
$type));
__construct(UrlFinderInterface $urlFinder, StoreManagerInterface $storeManager, CustomUrlLocatorInterface $customUrlLocator)
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
foreach( $_productCollection as $_product)() ?>" class $info