vendor/ezsystems/ezplatform-kernel/eZ/Publish/Core/Event/SectionService.php line 30

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\SectionService as SectionServiceInterface;
  9. use eZ\Publish\API\Repository\Values\Content\ContentInfo;
  10. use eZ\Publish\API\Repository\Values\Content\Location;
  11. use eZ\Publish\API\Repository\Values\Content\Section;
  12. use eZ\Publish\API\Repository\Values\Content\SectionCreateStruct;
  13. use eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct;
  14. use eZ\Publish\API\Repository\Events\Section\AssignSectionEvent;
  15. use eZ\Publish\API\Repository\Events\Section\AssignSectionToSubtreeEvent;
  16. use eZ\Publish\API\Repository\Events\Section\BeforeAssignSectionEvent;
  17. use eZ\Publish\API\Repository\Events\Section\BeforeAssignSectionToSubtreeEvent;
  18. use eZ\Publish\API\Repository\Events\Section\BeforeCreateSectionEvent;
  19. use eZ\Publish\API\Repository\Events\Section\BeforeDeleteSectionEvent;
  20. use eZ\Publish\API\Repository\Events\Section\BeforeUpdateSectionEvent;
  21. use eZ\Publish\API\Repository\Events\Section\CreateSectionEvent;
  22. use eZ\Publish\API\Repository\Events\Section\DeleteSectionEvent;
  23. use eZ\Publish\API\Repository\Events\Section\UpdateSectionEvent;
  24. use eZ\Publish\SPI\Repository\Decorator\SectionServiceDecorator;
  25. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  26. class SectionService extends SectionServiceDecorator
  27. {
  28.     /** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
  29.     protected $eventDispatcher;
  30.     public function __construct(
  31.         SectionServiceInterface $innerService,
  32.         EventDispatcherInterface $eventDispatcher
  33.     ) {
  34.         parent::__construct($innerService);
  35.         $this->eventDispatcher $eventDispatcher;
  36.     }
  37.     public function createSection(SectionCreateStruct $sectionCreateStruct): Section
  38.     {
  39.         $eventData = [$sectionCreateStruct];
  40.         $beforeEvent = new BeforeCreateSectionEvent(...$eventData);
  41.         $this->eventDispatcher->dispatch($beforeEvent);
  42.         if ($beforeEvent->isPropagationStopped()) {
  43.             return $beforeEvent->getSection();
  44.         }
  45.         $section $beforeEvent->hasSection()
  46.             ? $beforeEvent->getSection()
  47.             : $this->innerService->createSection($sectionCreateStruct);
  48.         $this->eventDispatcher->dispatch(
  49.             new CreateSectionEvent($section, ...$eventData)
  50.         );
  51.         return $section;
  52.     }
  53.     public function updateSection(
  54.         Section $section,
  55.         SectionUpdateStruct $sectionUpdateStruct
  56.     ): Section {
  57.         $eventData = [
  58.             $section,
  59.             $sectionUpdateStruct,
  60.         ];
  61.         $beforeEvent = new BeforeUpdateSectionEvent(...$eventData);
  62.         $this->eventDispatcher->dispatch($beforeEvent);
  63.         if ($beforeEvent->isPropagationStopped()) {
  64.             return $beforeEvent->getUpdatedSection();
  65.         }
  66.         $updatedSection $beforeEvent->hasUpdatedSection()
  67.             ? $beforeEvent->getUpdatedSection()
  68.             : $this->innerService->updateSection($section$sectionUpdateStruct);
  69.         $this->eventDispatcher->dispatch(
  70.             new UpdateSectionEvent($updatedSection, ...$eventData)
  71.         );
  72.         return $updatedSection;
  73.     }
  74.     public function assignSection(
  75.         ContentInfo $contentInfo,
  76.         Section $section
  77.     ): void {
  78.         $eventData = [
  79.             $contentInfo,
  80.             $section,
  81.         ];
  82.         $beforeEvent = new BeforeAssignSectionEvent(...$eventData);
  83.         $this->eventDispatcher->dispatch($beforeEvent);
  84.         if ($beforeEvent->isPropagationStopped()) {
  85.             return;
  86.         }
  87.         $this->innerService->assignSection($contentInfo$section);
  88.         $this->eventDispatcher->dispatch(
  89.             new AssignSectionEvent(...$eventData)
  90.         );
  91.     }
  92.     public function assignSectionToSubtree(
  93.         Location $location,
  94.         Section $section
  95.     ): void {
  96.         $eventData = [
  97.             $location,
  98.             $section,
  99.         ];
  100.         $beforeEvent = new BeforeAssignSectionToSubtreeEvent(...$eventData);
  101.         $this->eventDispatcher->dispatch($beforeEvent);
  102.         if ($beforeEvent->isPropagationStopped()) {
  103.             return;
  104.         }
  105.         $this->innerService->assignSectionToSubtree($location$section);
  106.         $this->eventDispatcher->dispatch(
  107.             new AssignSectionToSubtreeEvent(...$eventData)
  108.         );
  109.     }
  110.     public function deleteSection(Section $section): void
  111.     {
  112.         $eventData = [$section];
  113.         $beforeEvent = new BeforeDeleteSectionEvent(...$eventData);
  114.         $this->eventDispatcher->dispatch($beforeEvent);
  115.         if ($beforeEvent->isPropagationStopped()) {
  116.             return;
  117.         }
  118.         $this->innerService->deleteSection($section);
  119.         $this->eventDispatcher->dispatch(
  120.             new DeleteSectionEvent(...$eventData)
  121.         );
  122.     }
  123. }