vendor/ezsystems/ezplatform-kernel/eZ/Publish/Core/Event/UserPreferenceService.php line 17

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 eZ\Publish\Core\Event;
  8. use eZ\Publish\API\Repository\UserPreferenceService as UserPreferenceServiceInterface;
  9. use eZ\Publish\API\Repository\Events\UserPreference\BeforeSetUserPreferenceEvent;
  10. use eZ\Publish\API\Repository\Events\UserPreference\SetUserPreferenceEvent;
  11. use eZ\Publish\SPI\Repository\Decorator\UserPreferenceServiceDecorator;
  12. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  13. class UserPreferenceService extends UserPreferenceServiceDecorator
  14. {
  15.     /** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
  16.     protected $eventDispatcher;
  17.     public function __construct(
  18.         UserPreferenceServiceInterface $innerService,
  19.         EventDispatcherInterface $eventDispatcher
  20.     ) {
  21.         parent::__construct($innerService);
  22.         $this->eventDispatcher $eventDispatcher;
  23.     }
  24.     public function setUserPreference(array $userPreferenceSetStructs): void
  25.     {
  26.         $eventData = [$userPreferenceSetStructs];
  27.         $beforeEvent = new BeforeSetUserPreferenceEvent(...$eventData);
  28.         $this->eventDispatcher->dispatch($beforeEvent);
  29.         if ($beforeEvent->isPropagationStopped()) {
  30.             return;
  31.         }
  32.         $this->innerService->setUserPreference($userPreferenceSetStructs);
  33.         $this->eventDispatcher->dispatch(
  34.             new SetUserPreferenceEvent(...$eventData)
  35.         );
  36.     }
  37. }