Skip to content

Commit 3bc285f

Browse files
jbcrdamonsson
authored andcommitted
update to sitemap v2
1 parent 88319ab commit 3bc285f

3 files changed

Lines changed: 53 additions & 54 deletions

File tree

composer.json

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,35 @@
1212
"php": "^7.3",
1313
"league/csv": "^9.1",
1414
"friendsofsymfony/ckeditor-bundle": "^1.1|^2.0",
15-
"stefandoorn/sitemap-plugin": "^1.0||dev-master",
16-
"sylius/sylius": "^1.8"
15+
"stefandoorn/sitemap-plugin": "dev-master",
16+
"sylius/sylius": "^1.9"
1717
},
1818
"require-dev": {
19-
"behat/behat": "^3.6",
20-
"behat/mink": "^1.7",
21-
"behat/mink-browserkit-driver": "^1.3",
22-
"behat/mink-extension": "^2.2",
23-
"behat/mink-selenium2-driver": "^1.3",
19+
"behat/behat": "^3.7",
20+
"behat/mink": "^1.8",
21+
"behat/mink-selenium2-driver": "^1.4",
22+
"friends-of-behat/mink-browserkit-driver": "^1.4",
23+
"friends-of-behat/mink-debug-extension": "^2.0",
24+
"friends-of-behat/mink-extension": "^2.4",
2425
"friends-of-behat/page-object-extension": "^0.3",
2526
"friends-of-behat/suite-settings-extension": "^1.0",
26-
"friends-of-behat/symfony-extension": "^2.0",
27-
"friends-of-behat/variadic-extension": "^1.1",
28-
"lakion/mink-debug-extension": "^1.2.3",
29-
"lchrusciel/api-test-case": "^3.0",
27+
"friends-of-behat/symfony-extension": "^2.1",
28+
"friends-of-behat/variadic-extension": "^1.3",
29+
"lchrusciel/api-test-case": "^4.1",
3030
"matthiasnoback/symfony-config-test": "^3.0",
31-
"phpspec/phpspec": "^6.0",
31+
"phpspec/phpspec": "^7.0",
3232
"phpstan/phpstan": "^0.12",
33-
"phpstan/phpstan-doctrine": "^0.12",
34-
"phpstan/phpstan-symfony": "^0.12",
35-
"phpstan/phpstan-webmozart-assert": "^0.12",
36-
"phpunit/phpunit": "^6.5",
37-
"sensiolabs/security-checker": "^5.0",
38-
"sylius-labs/coding-standard": "^3.0",
39-
"symfony/browser-kit": "^4.4",
40-
"symfony/debug-bundle": "^4.4",
41-
"symfony/dotenv": "^4.4",
42-
"symfony/intl": "^4.4",
43-
"symfony/web-profiler-bundle": "^4.4",
44-
"symfony/web-server-bundle": "^4.4"
33+
"phpstan/phpstan-doctrine": "^0.12.32",
34+
"phpstan/phpstan-symfony": "^0.12.21",
35+
"phpstan/phpstan-webmozart-assert": "^0.12.12",
36+
"phpunit/phpunit": "^8.0||^9.0",
37+
"sylius-labs/coding-standard": "^3.2",
38+
"symfony/browser-kit": "^4.4||^5.2",
39+
"symfony/debug-bundle": "^4.4||^5.2",
40+
"symfony/dotenv": "^4.4||^5.2",
41+
"symfony/intl": "^4.4||^5.2",
42+
"symfony/web-profiler-bundle": "^4.4||^5.2",
43+
"symfony/web-server-bundle": "^4.4||^5.2"
4544
},
4645
"conflict": {
4746
"symfony/symfony": "4.1.8",

src/SitemapProvider/PageUrlProvider.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface;
1717
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface;
1818
use Doctrine\Common\Collections\Collection;
19-
use SitemapPlugin\Factory\SitemapUrlFactoryInterface;
19+
use SitemapPlugin\Factory\UrlFactoryInterface;
20+
use SitemapPlugin\Model\AlternativeUrl;
2021
use SitemapPlugin\Model\ChangeFrequency;
21-
use SitemapPlugin\Model\SitemapUrlInterface;
22+
use SitemapPlugin\Model\SitemapInterface;
23+
use SitemapPlugin\Model\UrlInterface;
2224
use SitemapPlugin\Provider\UrlProviderInterface;
2325
use Sylius\Component\Channel\Context\ChannelContextInterface;
2426
use Sylius\Component\Core\Model\ChannelInterface;
@@ -35,7 +37,7 @@ final class PageUrlProvider implements UrlProviderInterface
3537
/** @var RouterInterface */
3638
private $router;
3739

38-
/** @var SitemapUrlFactoryInterface */
40+
/** @var UrlFactoryInterface */
3941
private $sitemapUrlFactory;
4042

4143
/** @var LocaleContextInterface */
@@ -47,7 +49,7 @@ final class PageUrlProvider implements UrlProviderInterface
4749
public function __construct(
4850
PageRepositoryInterface $pageRepository,
4951
RouterInterface $router,
50-
SitemapUrlFactoryInterface $sitemapUrlFactory,
52+
UrlFactoryInterface $sitemapUrlFactory,
5153
LocaleContextInterface $localeContext,
5254
ChannelContextInterface $channelContext
5355
) {
@@ -63,7 +65,7 @@ public function getName(): string
6365
return 'cms_pages';
6466
}
6567

66-
public function generate(): iterable
68+
public function generate(ChannelInterface $channel): iterable
6769
{
6870
$urls = [];
6971

@@ -101,9 +103,14 @@ private function getLocaleCodes(): array
101103
})->toArray();
102104
}
103105

104-
private function createPageUrl(PageInterface $page): SitemapUrlInterface
106+
private function createPageUrl(PageInterface $page): UrlInterface
105107
{
106-
$pageUrl = $this->sitemapUrlFactory->createNew();
108+
$location = $this->router->generate('bitbag_sylius_cms_plugin_shop_page_show', [
109+
'slug' => $page->getTranslation($this->localeContext->getLocaleCode())->getSlug(),
110+
'_locale' => $this->localeContext->getLocaleCode(),
111+
]);
112+
113+
$pageUrl = $this->sitemapUrlFactory->createNew($location);
107114

108115
$pageUrl->setChangeFrequency(ChangeFrequency::daily());
109116
$pageUrl->setPriority(0.7);
@@ -116,7 +123,7 @@ private function createPageUrl(PageInterface $page): SitemapUrlInterface
116123

117124
/** @var PageTranslationInterface $translation */
118125
foreach ($this->getTranslations($page) as $translation) {
119-
if (!$translation->getLocale() || !$this->localeInLocaleCodes($translation)) {
126+
if (!$translation->getLocale() || !$this->localeInLocaleCodes($translation) || $translation->getLocale() === $this->localeContext->getLocaleCode()) {
120127
continue;
121128
}
122129

@@ -125,13 +132,7 @@ private function createPageUrl(PageInterface $page): SitemapUrlInterface
125132
'_locale' => $translation->getLocale(),
126133
]);
127134

128-
if ($translation->getLocale() === $this->localeContext->getLocaleCode()) {
129-
$pageUrl->setLocalization($location);
130-
131-
continue;
132-
}
133-
134-
$pageUrl->addAlternative($location, $translation->getLocale());
135+
$pageUrl->addAlternative(new AlternativeUrl($location, $translation->getLocale()));
135136
}
136137

137138
return $pageUrl;

src/SitemapProvider/SectionUrlProvider.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
use BitBag\SyliusCmsPlugin\Entity\SectionTranslationInterface;
1717
use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface;
1818
use Doctrine\Common\Collections\Collection;
19-
use SitemapPlugin\Factory\SitemapUrlFactoryInterface;
19+
use SitemapPlugin\Factory\UrlFactoryInterface;
20+
use SitemapPlugin\Model\AlternativeUrl;
2021
use SitemapPlugin\Model\ChangeFrequency;
21-
use SitemapPlugin\Model\SitemapUrlInterface;
22+
use SitemapPlugin\Model\UrlInterface;
2223
use SitemapPlugin\Provider\UrlProviderInterface;
2324
use Sylius\Component\Channel\Context\ChannelContextInterface;
2425
use Sylius\Component\Core\Model\ChannelInterface;
@@ -35,7 +36,7 @@ final class SectionUrlProvider implements UrlProviderInterface
3536
/** @var RouterInterface */
3637
private $router;
3738

38-
/** @var SitemapUrlFactoryInterface */
39+
/** @var UrlFactoryInterface */
3940
private $sitemapUrlFactory;
4041

4142
/** @var LocaleContextInterface */
@@ -47,7 +48,7 @@ final class SectionUrlProvider implements UrlProviderInterface
4748
public function __construct(
4849
SectionRepositoryInterface $sectionRepository,
4950
RouterInterface $router,
50-
SitemapUrlFactoryInterface $sitemapUrlFactory,
51+
UrlFactoryInterface $sitemapUrlFactory,
5152
LocaleContextInterface $localeContext,
5253
ChannelContextInterface $channelContext
5354
) {
@@ -63,7 +64,7 @@ public function getName(): string
6364
return 'cms_sections';
6465
}
6566

66-
public function generate(): iterable
67+
public function generate(ChannelInterface $channel): iterable
6768
{
6869
$urls = [];
6970

@@ -101,16 +102,20 @@ private function getLocaleCodes(): array
101102
})->toArray();
102103
}
103104

104-
private function createSectionUrl(SectionInterface $section): SitemapUrlInterface
105+
private function createSectionUrl(SectionInterface $section): UrlInterface
105106
{
106-
$url = $this->sitemapUrlFactory->createNew();
107+
$location = $this->router->generate('bitbag_sylius_cms_plugin_shop_section_show', [
108+
'code' => $section->getCode(),
109+
'_locale' => $this->localeContext->getLocaleCode(),
110+
]);
111+
$url = $this->sitemapUrlFactory->createNew($location);
107112

108113
$url->setChangeFrequency(ChangeFrequency::daily());
109114
$url->setPriority(0.7);
110115

111116
/** @var SectionTranslationInterface $translation */
112117
foreach ($this->getTranslations($section) as $translation) {
113-
if (!$translation->getLocale() || !$this->localeInLocaleCodes($translation)) {
118+
if (!$translation->getLocale() || !$this->localeInLocaleCodes($translation) || $translation->getLocale() === $this->localeContext->getLocaleCode()) {
114119
continue;
115120
}
116121

@@ -119,13 +124,7 @@ private function createSectionUrl(SectionInterface $section): SitemapUrlInterfac
119124
'_locale' => $translation->getLocale(),
120125
]);
121126

122-
if ($translation->getLocale() === $this->localeContext->getLocaleCode()) {
123-
$url->setLocalization($location);
124-
125-
continue;
126-
}
127-
128-
$url->addAlternative($location, $translation->getLocale());
127+
$url->addAlternative(new AlternativeUrl($location, $translation->getLocale()));
129128
}
130129

131130
return $url;

0 commit comments

Comments
 (0)