|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Event; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Repository\Decorator\BookmarkServiceDecorator; |
|
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
13
|
|
|
use eZ\Publish\API\Repository\BookmarkService as BookmarkServiceInterface; |
|
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
15
|
|
|
use eZ\Publish\Core\Event\Bookmark\BeforeCreateBookmarkEvent; |
|
16
|
|
|
use eZ\Publish\Core\Event\Bookmark\BeforeDeleteBookmarkEvent; |
|
17
|
|
|
use eZ\Publish\Core\Event\Bookmark\BookmarkEvents; |
|
18
|
|
|
use eZ\Publish\Core\Event\Bookmark\CreateBookmarkEvent; |
|
19
|
|
|
use eZ\Publish\Core\Event\Bookmark\DeleteBookmarkEvent; |
|
20
|
|
|
|
|
21
|
|
|
class BookmarkService extends BookmarkServiceDecorator implements BookmarkServiceInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $eventDispatcher; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct( |
|
29
|
|
|
BookmarkServiceInterface $innerService, |
|
30
|
|
|
EventDispatcherInterface $eventDispatcher |
|
31
|
|
|
) { |
|
32
|
|
|
parent::__construct($innerService); |
|
33
|
|
|
|
|
34
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function createBookmark(Location $location): void |
|
38
|
|
|
{ |
|
39
|
|
|
$eventData = [$location]; |
|
40
|
|
|
|
|
41
|
|
|
$beforeEvent = new BeforeCreateBookmarkEvent(...$eventData); |
|
42
|
|
|
if ($this->eventDispatcher->dispatch(BookmarkEvents::BEFORE_CREATE_BOOKMARK, $beforeEvent)->isPropagationStopped()) { |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
parent::createBookmark($location); |
|
47
|
|
|
|
|
48
|
|
|
$this->eventDispatcher->dispatch( |
|
49
|
|
|
BookmarkEvents::CREATE_BOOKMARK, |
|
50
|
|
|
new CreateBookmarkEvent(...$eventData) |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function deleteBookmark(Location $location): void |
|
55
|
|
|
{ |
|
56
|
|
|
$eventData = [$location]; |
|
57
|
|
|
|
|
58
|
|
|
$beforeEvent = new BeforeDeleteBookmarkEvent(...$eventData); |
|
59
|
|
|
if ($this->eventDispatcher->dispatch(BookmarkEvents::BEFORE_DELETE_BOOKMARK, $beforeEvent)->isPropagationStopped()) { |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
parent::deleteBookmark($location); |
|
64
|
|
|
|
|
65
|
|
|
$this->eventDispatcher->dispatch( |
|
66
|
|
|
BookmarkEvents::DELETE_BOOKMARK, |
|
67
|
|
|
new DeleteBookmarkEvent(...$eventData) |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|