urlFinder = $urlFinder; } /** * @inheritdoc */ public function resolve( Field $field, $context, ResolveInfo $info, array $value = null, array $args = null ): array { if (!isset($value['model'])) { throw new LocalizedException(__('"model" value should be specified')); } /** @var AbstractModel $entity */ $entity = $value['model']; $entityId = $entity->getEntityId(); $urlRewriteCollection = $this->urlFinder->findAllByData([UrlRewriteDTO::ENTITY_ID => $entityId]); $urlRewrites = []; /** @var UrlRewriteDTO $urlRewrite */ foreach ($urlRewriteCollection as $urlRewrite) { if ($urlRewrite->getRedirectType() !== 0) { continue; } $urlRewrites[] = [ 'url' => $urlRewrite->getRequestPath(), 'parameters' => $this->getUrlParameters($urlRewrite->getTargetPath()) ]; } return $urlRewrites; } /** * Parses target path and extracts parameters * * @param string $targetPath * @return array */ private function getUrlParameters(string $targetPath): array { $urlParameters = []; $targetPathParts = explode('/', trim($targetPath, '/')); for ($i = 3; ($i < sizeof($targetPathParts) - 1); $i += 2) { $urlParameters[] = [ 'name' => $targetPathParts[$i], 'value' => $targetPathParts[$i + 1] ]; } return $urlParameters; } }