Skip to content

Commit

Permalink
add alternates links to sitemap provider and fix sulu compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jun 20, 2017
1 parent 5eab8c5 commit c4f801b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define([
});

if (!!component.data.type && component.data.type.name === 'ghost') {
component.data['_hash'] = null;
delete component.data['_hash'];
}

return ArticleManager.save(component.data, component.data.id, component.options.locale, action);
Expand Down
3 changes: 3 additions & 0 deletions Resources/public/js/components/articles/edit/details/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ define([

var data = this.options.adapter.prepareData(this.data, this);
if (data.type && data.type.name === 'ghost') {
var titleProperty = this.getTitleProperty(),
pageTitleProperty = this.getPageTitleProperty();

this.ghost = {
locale: data.type.value,
title: titleProperty ? data[titleProperty.name] : '',
Expand Down
45 changes: 43 additions & 2 deletions Sitemap/ArticleSitemapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocumentInterface;
use Sulu\Bundle\ArticleBundle\Document\Index\DocumentFactoryInterface;
use Sulu\Bundle\WebsiteBundle\Sitemap\Sitemap;
use Sulu\Bundle\WebsiteBundle\Sitemap\SitemapAlternateLink;
use Sulu\Bundle\WebsiteBundle\Sitemap\SitemapProviderInterface;
use Sulu\Bundle\WebsiteBundle\Sitemap\SitemapUrl;

Expand Down Expand Up @@ -48,7 +49,7 @@ public function __construct(Manager $manager, DocumentFactoryInterface $document
/**
* {@inheritdoc}
*/
public function build($page, $portalKey, $locale)
public function build($page, $portalKey)
{
$repository = $this->manager->getRepository($this->documentFactory->getClass('article'));

Expand All @@ -58,17 +59,57 @@ public function build($page, $portalKey, $locale)
$size = 1000;
do {
$bulk = $this->getBulk($repository, $from, $size);
/** @var SitemapUrl[] $alternatives */
$sitemapUrlListByUuid = [];

/** @var ArticleViewDocumentInterface $item */
foreach ($bulk as $item) {
$result[] = new SitemapUrl($item->getRoutePath(), $item->getChanged());
$sitemapUrl = new SitemapUrl($item->getRoutePath(), $item->getLocale(), $item->getChanged());
$result[] = $sitemapUrl;

if (!isset($sitemapUrlListByUuid[$item->getUuid()])) {
$sitemapUrlListByUuid[$item->getUuid()] = [];
}

$sitemapUrlListByUuid[$item->getUuid()] = $this->setAlternatives(
$sitemapUrlListByUuid[$item->getUuid()],
$sitemapUrl
);
}

$from += $size;
} while ($bulk->count() > $from || $from > self::PAGE_SIZE);

return $result;
}

/**
* Set alternatives to sitemap url.
*
* @param SitemapUrl[] $sitemapUrlList
* @param SitemapUrl $sitemapUrl
*
* @return SitemapUrl[]
*/
private function setAlternatives(array $sitemapUrlList, SitemapUrl $sitemapUrl)
{
foreach ($sitemapUrlList as $sitemapUrlFromList) {
// Add current as alternative to exist.
$sitemapUrlFromList->addAlternateLink(
new SitemapAlternateLink($sitemapUrl->getLoc(), $sitemapUrl->getLocale())
);

// Add others as alternative to current.
$sitemapUrl->addAlternateLink(
new SitemapAlternateLink($sitemapUrlFromList->getLoc(), $sitemapUrlFromList->getLocale())
);
}

$sitemapUrlList[] = $sitemapUrl;

return $sitemapUrlList;
}

private function getBulk(Repository $repository, $from, $size)
{
$search = $repository->createSearch()
Expand Down

0 comments on commit c4f801b

Please sign in to comment.