-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[shopsys] added hreflang feature (#2970)
- Loading branch information
Showing
21 changed files
with
246 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrontendApiBundle\Model\Resolver\Image; | ||
|
||
use GraphQL\Executor\Promise\Promise; | ||
use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPage; | ||
use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageFacade; | ||
|
||
class SeoPageImagesQuery extends ImagesQuery | ||
{ | ||
/** | ||
* @param \Shopsys\FrameworkBundle\Model\Seo\Page\SeoPage $seoPage | ||
* @return \GraphQL\Executor\Promise\Promise | ||
*/ | ||
public function ogImageBySeoPageQuery(SeoPage $seoPage): Promise | ||
{ | ||
return $this->mainImageByEntityPromiseQuery( | ||
$seoPage, | ||
SeoPageFacade::IMAGE_TYPE_OG, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Model/Resolver/SeoPage/Exception/SeoPageNotFoundUserError.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrontendApiBundle\Model\Resolver\SeoPage\Exception; | ||
|
||
use Shopsys\FrontendApiBundle\Model\Error\EntityNotFoundUserError; | ||
use Shopsys\FrontendApiBundle\Model\Error\UserErrorWithCodeInterface; | ||
|
||
class SeoPageNotFoundUserError extends EntityNotFoundUserError implements UserErrorWithCodeInterface | ||
{ | ||
protected const CODE = 'seo-page-not-found'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getUserErrorCode(): string | ||
{ | ||
return static::CODE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrontendApiBundle\Model\Resolver\SeoPage; | ||
|
||
use Shopsys\FrameworkBundle\Component\Domain\Domain; | ||
use Shopsys\FrameworkBundle\Model\Seo\Page\Exception\SeoPageNotFoundException; | ||
use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPage; | ||
use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageFacade; | ||
use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageSlugTransformer; | ||
use Shopsys\FrontendApiBundle\Model\Resolver\AbstractQuery; | ||
use Shopsys\FrontendApiBundle\Model\Resolver\SeoPage\Exception\SeoPageNotFoundUserError; | ||
|
||
class SeoPageQuery extends AbstractQuery | ||
{ | ||
/** | ||
* @param \Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageFacade $seoPageFacade | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain | ||
*/ | ||
public function __construct( | ||
protected readonly SeoPageFacade $seoPageFacade, | ||
protected readonly Domain $domain, | ||
) { | ||
} | ||
|
||
/** | ||
* @param string $pageSlug | ||
* @return \Shopsys\FrameworkBundle\Model\Seo\Page\SeoPage | ||
*/ | ||
public function seoPageByPageSlugQuery(string $pageSlug): SeoPage | ||
{ | ||
$domainId = $this->domain->getId(); | ||
|
||
try { | ||
$slug = SeoPageSlugTransformer::transformFriendlyUrlToSeoPageSlug($pageSlug); | ||
$seoPage = $this->seoPageFacade->getByDomainIdAndPageSlug($domainId, $slug); | ||
} catch (SeoPageNotFoundException $seoPageNotFoundException) { | ||
throw new SeoPageNotFoundUserError($seoPageNotFoundException->getMessage()); | ||
} | ||
|
||
return $seoPage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrontendApiBundle\Model\Resolver\SeoPage; | ||
|
||
use Overblog\GraphQLBundle\Resolver\ResolverMap; | ||
use Shopsys\FrameworkBundle\Component\Domain\Domain; | ||
use Shopsys\FrameworkBundle\Model\Seo\HreflangLinksFacade; | ||
use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPage; | ||
|
||
class SeoPageResolverMap extends ResolverMap | ||
{ | ||
/** | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain | ||
* @param \Shopsys\FrameworkBundle\Model\Seo\HreflangLinksFacade $hreflangLinksFacade | ||
*/ | ||
public function __construct( | ||
protected readonly Domain $domain, | ||
protected readonly HreflangLinksFacade $hreflangLinksFacade, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function map(): array | ||
{ | ||
return [ | ||
'SeoPage' => [ | ||
'title' => fn (SeoPage $seoPage) => $seoPage->getSeoTitle($this->domain->getId()), | ||
'metaDescription' => fn (SeoPage $seoPage) => $seoPage->getSeoMetaDescription($this->domain->getId()), | ||
'canonicalUrl' => fn (SeoPage $seoPage) => $seoPage->getCanonicalUrl($this->domain->getId()), | ||
'ogTitle' => fn (SeoPage $seoPage) => $seoPage->getSeoOgTitle($this->domain->getId()), | ||
'ogDescription' => fn (SeoPage $seoPage) => $seoPage->getSeoOgDescription($this->domain->getId()), | ||
'hreflangLinks' => fn (SeoPage $seoPage) => $this->hreflangLinksFacade->getForSeoPage($seoPage, $this->domain->getId()), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Resources/config/graphql-types/Hreflang/HreflangDecorator.types.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
HreflangDecorator: | ||
type: interface | ||
decorator: true | ||
config: | ||
description: "Represents entity able to return alternate links for hreflang meta tags" | ||
fields: | ||
hreflangLinks: | ||
type: "[HreflangLink!]!" | ||
description: "Alternate links for hreflang meta tags" |
11 changes: 11 additions & 0 deletions
11
src/Resources/config/graphql-types/Hreflang/HreflangLinkDecorator.types.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
HreflangLinkDecorator: | ||
type: object | ||
decorator: true | ||
config: | ||
fields: | ||
hreflang: | ||
type: "String!" | ||
description: "Language code for hreflang meta tag" | ||
href: | ||
type: "String!" | ||
description: "URL for hreflang meta tag" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ MainVariantDecorator: | |
type: '[Variant!]!' | ||
interfaces: | ||
- 'Product' | ||
- 'Hreflang' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ RegularProductDecorator: | |
config: | ||
interfaces: | ||
- 'Product' | ||
- 'Hreflang' |
Oops, something went wrong.