Skip to content

Commit

Permalink
[Feature] Add event to notes (#73)
Browse files Browse the repository at this point in the history
* Add event to notes

* Fix WorkflowAction in Controller
  • Loading branch information
mattamon authored May 23, 2024
1 parent e293cf6 commit 2f4d997
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
40 changes: 40 additions & 0 deletions src/Note/Event/NoteEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Note\Event;

use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\Note;


final class NoteEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.note';
public function __construct(
private readonly Note $note
)
{
parent::__construct($note);
}

/**
* Use this to get additional infos out of the response object
*/
public function getNote(): Note
{
return $this->note;
}
}
24 changes: 21 additions & 3 deletions src/Note/Service/NoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Note\Event\NoteEvent;
use Pimcore\Bundle\StudioBackendBundle\Note\Hydrator\NoteHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\Note\Repository\NoteRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElement;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteParameters;
use Pimcore\Bundle\StudioBackendBundle\Note\Response\Collection;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\CreateNote;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\Note;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* @internal
Expand All @@ -34,7 +36,8 @@

public function __construct(
private NoteRepositoryInterface $noteRepository,
private NoteHydratorInterface $noteHydrator
private NoteHydratorInterface $noteHydrator,
private EventDispatcherInterface $eventDispatcher
)
{
}
Expand All @@ -53,7 +56,15 @@ public function listNotes(NoteElement $noteElement, NoteParameters $parameters):
$noteListing = $this->noteRepository->listNotes($noteElement, $parameters);
$notes = [];
foreach ($noteListing as $note) {
$notes[] = $this->noteHydrator->hydrate($note);

$note = $this->noteHydrator->hydrate($note);

$this->eventDispatcher->dispatch(
new NoteEvent($note),
NoteEvent::EVENT_NAME
);

$notes[] = $note;
}

return new Collection(
Expand All @@ -74,6 +85,13 @@ public function deleteNote(int $id): void

private function getNote(int $id): Note
{
return $this->noteHydrator->hydrate($this->noteRepository->getNote($id));
$note = $this->noteHydrator->hydrate($this->noteRepository->getNote($id));

$this->eventDispatcher->dispatch(
new NoteEvent($note),
NoteEvent::EVENT_NAME
);

return $note;
}
}
2 changes: 1 addition & 1 deletion src/Workflow/Controller/SubmitActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Request\WorkflowActionRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Workflow\Attributes\Request\WorkflowActionRequestBody;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
Expand Down

0 comments on commit 2f4d997

Please sign in to comment.