Skip to content

Commit

Permalink
Merge pull request #3407 from insiders/pagepart-admin-event
Browse files Browse the repository at this point in the history
[PagePartBundle] Add page to PagePartEvent
  • Loading branch information
acrobat committed Apr 28, 2024
2 parents cb6ecb4 + 62df4bf commit 2d71d76
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions UPGRADE-7.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ FormBundle
-----------

- The frontendformobject view variable of form pagepart templates is deprecated and will be removed in 8.0. There is no replacement for this variable.

PagePartBundle
--------------

- Not passing a HasPagePartsInterface as second parameter in PagePartEvent is deprecated and will be required in 8.0.
15 changes: 14 additions & 1 deletion src/Kunstmaan/PagePartBundle/Event/PagePartEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Kunstmaan\PagePartBundle\Event;

use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface;
use Kunstmaan\PagePartBundle\Helper\PagePartInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\EventDispatcher\Event;
Expand All @@ -18,9 +19,16 @@ final class PagePartEvent extends Event
*/
private $response;

public function __construct(PagePartInterface $pagePart)
private ?HasPagePartsInterface $page;

public function __construct(PagePartInterface $pagePart, ?HasPagePartsInterface $page = null)
{
$this->pagePart = $pagePart;
$this->page = $page;

if ($page === null) {
trigger_deprecation('kunstmaan/pagepart-bundle', '7.2', 'Not passing a HasPagePartsInterface as second parameter is deprecated and will be required in 8.0.');
}
}

public function getPagePart(): PagePartInterface
Expand All @@ -42,4 +50,9 @@ public function setResponse(Response $response)
{
$this->response = $response;
}

public function getPage(): ?HasPagePartsInterface
{
return $this->page;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function persist(Request $request)
}

if (isset($pagePart)) {
$this->container->get('event_dispatcher')->dispatch(new PagePartEvent($pagePart), Events::POST_PERSIST);
$this->container->get('event_dispatcher')->dispatch(new PagePartEvent($pagePart, $this->page), Events::POST_PERSIST);
}
}
}
Expand Down

0 comments on commit 2d71d76

Please sign in to comment.