vendor/ibexa/personalization/src/lib/Event/Subscriber/ObjectStateEventSubscriber.php line 48

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\Personalization\Event\Subscriber;
  8. use Ibexa\Contracts\Core\Repository\ContentService as CoreContentService;
  9. use Ibexa\Contracts\Core\Repository\Events\ObjectState\SetContentStateEvent;
  10. use Ibexa\Personalization\Config\ItemType\IncludedItemTypeResolverInterface;
  11. use Ibexa\Personalization\Event\PersonalizationEvent;
  12. use Ibexa\Personalization\Service\Content\ContentServiceInterface;
  13. use Ibexa\Personalization\Service\Setting\SettingServiceInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. final class ObjectStateEventSubscriber implements EventSubscriberInterface
  16. {
  17.     private CoreContentService $coreContentService;
  18.     private ContentServiceInterface $contentService;
  19.     private IncludedItemTypeResolverInterface $includedItemTypeResolver;
  20.     private SettingServiceInterface $settingService;
  21.     public function __construct(
  22.         CoreContentService $coreContentService,
  23.         ContentServiceInterface $contentService,
  24.         IncludedItemTypeResolverInterface $includedItemTypeResolver,
  25.         SettingServiceInterface $settingService
  26.     ) {
  27.         $this->coreContentService $coreContentService;
  28.         $this->contentService $contentService;
  29.         $this->includedItemTypeResolver $includedItemTypeResolver;
  30.         $this->settingService $settingService;
  31.     }
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             SetContentStateEvent::class => ['onSetContentState'PersonalizationEvent::DEFAULT_PRIORITY],
  36.         ];
  37.     }
  38.     public function onSetContentState(SetContentStateEvent $event): void
  39.     {
  40.         if (!$this->settingService->isInstallationKeyFound()) {
  41.             return;
  42.         }
  43.         $content $this->coreContentService->loadContentByContentInfo($event->getContentInfo());
  44.         if (!$this->includedItemTypeResolver->isContentIncluded($content)) {
  45.             return;
  46.         }
  47.         $this->contentService->updateContent($content);
  48.     }
  49. }
  50. class_alias(ObjectStateEventSubscriber::class, 'EzSystems\EzRecommendationClient\Event\Subscriber\ObjectStateEventSubscriber');