-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented multilingual articles (#68)
* Implemented multilingual articles * Fixed style ci * Fixed style ci * Fixed comment * Correct index * Built and clean up * Fixed tests * Code clean up * Added multilingual tests * Fixed style CI * Removed not used imports * Increased memory to 2048 * Removed line break * Fixed tab language switch bug * Built js files * Add comment to linked issue * Upgrade notes for 0.0.2 * Code clean up * Fixed bug with route path generation * Fixed bug when switching language
- Loading branch information
1 parent
bcd4348
commit bec7610
Showing
38 changed files
with
851 additions
and
182 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,130 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ArticleBundle\Document\Index; | ||
|
||
use ONGR\ElasticsearchBundle\Service\Manager; | ||
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument; | ||
use Sulu\Bundle\ArticleBundle\Document\Index\Factory\ExcerptFactory; | ||
use Sulu\Bundle\ArticleBundle\Document\Index\Factory\SeoFactory; | ||
use Sulu\Bundle\SecurityBundle\UserManager\UserManager; | ||
use Sulu\Component\Content\Document\LocalizationState; | ||
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface; | ||
use Sulu\Component\DocumentManager\DocumentManagerInterface; | ||
use Sulu\Component\Localization\Localization; | ||
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
/** | ||
* Provides methods to index articles. | ||
*/ | ||
class ArticleGhostIndexer extends ArticleIndexer | ||
{ | ||
/** | ||
* @var WebspaceManagerInterface | ||
*/ | ||
private $webspaceManager; | ||
|
||
/** | ||
* @var DocumentManagerInterface | ||
*/ | ||
private $documentManager; | ||
|
||
/** | ||
* @param StructureMetadataFactoryInterface $structureMetadataFactory | ||
* @param UserManager $userManager | ||
* @param DocumentFactoryInterface $documentFactory | ||
* @param Manager $manager | ||
* @param ExcerptFactory $excerptFactory | ||
* @param SeoFactory $seoFactory | ||
* @param EventDispatcherInterface $eventDispatcher | ||
* @param TranslatorInterface $translator | ||
* @param array $typeConfiguration | ||
* @param WebspaceManagerInterface $webspaceManager | ||
* @param DocumentManagerInterface $documentManager | ||
*/ | ||
public function __construct( | ||
StructureMetadataFactoryInterface $structureMetadataFactory, | ||
UserManager $userManager, | ||
DocumentFactoryInterface $documentFactory, | ||
Manager $manager, | ||
ExcerptFactory $excerptFactory, | ||
SeoFactory $seoFactory, | ||
EventDispatcherInterface $eventDispatcher, | ||
TranslatorInterface $translator, | ||
array $typeConfiguration, | ||
WebspaceManagerInterface $webspaceManager, | ||
DocumentManagerInterface $documentManager | ||
) { | ||
parent::__construct( | ||
$structureMetadataFactory, | ||
$userManager, | ||
$documentFactory, | ||
$manager, | ||
$excerptFactory, | ||
$seoFactory, | ||
$eventDispatcher, | ||
$translator, | ||
$typeConfiguration | ||
); | ||
|
||
$this->webspaceManager = $webspaceManager; | ||
$this->documentManager = $documentManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function index(ArticleDocument $document) | ||
{ | ||
$article = $this->createOrUpdateArticle($document, $document->getLocale()); | ||
$this->createOrUpdateGhosts($document); | ||
$this->dispatchIndexEvent($document, $article); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function remove($document) | ||
{ | ||
foreach ($this->webspaceManager->getAllLocalizations() as $localization) { | ||
$articleId = $this->getArticleId($document->getUuid(), $localization->getLocale()); | ||
$this->removeArticle($articleId); | ||
} | ||
} | ||
|
||
/** | ||
* @param ArticleDocument $document | ||
*/ | ||
private function createOrUpdateGhosts(ArticleDocument $document) | ||
{ | ||
$documentLocale = $document->getLocale(); | ||
/** @var Localization $localization */ | ||
foreach ($this->webspaceManager->getAllLocalizations() as $localization) { | ||
$locale = $localization->getLocale(); | ||
if ($documentLocale !== $locale) { | ||
// Try index the article ghosts. | ||
$this->createOrUpdateArticle( | ||
$this->documentManager->find( | ||
$document->getUuid(), | ||
$locale, | ||
[ | ||
'load_ghost_content' => true, | ||
] | ||
), | ||
$localization->getLocale(), | ||
LocalizationState::GHOST | ||
); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.