34 lines
786 B
PHP
34 lines
786 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\MultiLocaleTranslation\Plugin\Blog;
|
|
|
|
use Esun\MultiLocaleTranslation\Model\BlogPostTranslationApplier;
|
|
use Mageplaza\Blog\Model\ResourceModel\Post\Collection;
|
|
|
|
class ApplyStoreTranslationToPostCollection
|
|
{
|
|
private bool $applying = false;
|
|
|
|
public function __construct(
|
|
private readonly BlogPostTranslationApplier $translationApplier
|
|
) {
|
|
}
|
|
|
|
public function afterLoad(Collection $subject, Collection $result): Collection
|
|
{
|
|
if ($this->applying) {
|
|
return $result;
|
|
}
|
|
|
|
$this->applying = true;
|
|
try {
|
|
$this->translationApplier->applyMany($result->getItems());
|
|
} finally {
|
|
$this->applying = false;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|