37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\MultiLocaleTranslation\Plugin\Wiki;
|
|
|
|
use Esun\MultiLocaleTranslation\Model\CmsTranslationRepository;
|
|
use Esun\MultiLocaleTranslation\Model\WikiTranslationApplier;
|
|
use Esun\Wiki\Model\Category;
|
|
use Esun\Wiki\Model\Homepage;
|
|
|
|
class ApplyWikiTranslation
|
|
{
|
|
public function __construct(
|
|
private readonly WikiTranslationApplier $translationApplier,
|
|
private readonly CmsTranslationRepository $translationRepository
|
|
) {
|
|
}
|
|
|
|
public function afterLoad(Category $subject, Category $result): Category
|
|
{
|
|
$this->translationApplier->apply($result);
|
|
return $result;
|
|
}
|
|
|
|
public function afterDelete(Category $subject, Category $result): Category
|
|
{
|
|
$this->translationRepository->clearEntityTranslations(
|
|
(int)$subject->getId(),
|
|
$subject instanceof Homepage
|
|
? CmsTranslationRepository::ENTITY_WIKI_HOMEPAGE
|
|
: CmsTranslationRepository::ENTITY_WIKI_CATEGORY
|
|
);
|
|
return $result;
|
|
}
|
|
}
|