Skip to content

Commit 1dbd41f

Browse files
adamwojswebhdx
authored andcommitted
IBX-7450: Dispatched event when focus mode changed its state (#1116)
* IBX-7450: Dispatched event when focus mode changed its state * fixup! IBX-7450: Dispatched event when focus mode changed its state
1 parent 7b8432e commit 1dbd41f

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,11 @@ parameters:
940940
count: 1
941941
path: src/bundle/Controller/UrlAliasController.php
942942

943+
-
944+
message: "#^Parameter \\#1 \\$enabled of class Ibexa\\\\Contracts\\\\AdminUi\\\\Event\\\\FocusModeChangedEvent constructor expects bool, bool\\|null given\\.$#"
945+
count: 1
946+
path: src/bundle/Controller/User/FocusModeController.php
947+
943948
-
944949
message: "#^Cannot access property \\$name on Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\|null\\.$#"
945950
count: 1

src/bundle/Controller/User/FocusModeController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use Ibexa\AdminUi\Form\Type\User\FocusModeChangeType;
1313
use Ibexa\AdminUi\UserSetting\FocusMode;
1414
use Ibexa\Contracts\AdminUi\Controller\Controller;
15+
use Ibexa\Contracts\AdminUi\Event\FocusModeChangedEvent;
1516
use Ibexa\User\UserSetting\UserSettingService;
17+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1618
use Symfony\Component\HttpFoundation\RedirectResponse;
1719
use Symfony\Component\HttpFoundation\Request;
1820
use Symfony\Component\HttpFoundation\Response;
@@ -22,6 +24,8 @@ final class FocusModeController extends Controller
2224
{
2325
private const RETURN_PATH_PARAM = 'returnPath';
2426

27+
private EventDispatcherInterface $eventDispatcher;
28+
2529
private UserSettingService $userSettingService;
2630

2731
private UrlMatcherInterface $urlMatcher;
@@ -33,10 +37,12 @@ final class FocusModeController extends Controller
3337
* @param iterable<\Ibexa\Contracts\AdminUi\FocusMode\RedirectStrategyInterface> $redirectStrategies
3438
*/
3539
public function __construct(
40+
EventDispatcherInterface $eventDispatcher,
3641
UserSettingService $userSettingService,
3742
UrlMatcherInterface $urlMatcher,
3843
iterable $redirectStrategies
3944
) {
45+
$this->eventDispatcher = $eventDispatcher;
4046
$this->userSettingService = $userSettingService;
4147
$this->urlMatcher = $urlMatcher;
4248
$this->redirectStrategies = $redirectStrategies;
@@ -70,6 +76,8 @@ public function changeAction(Request $request, ?string $returnPath): Response
7076
$data->isEnabled() ? FocusMode::FOCUS_MODE_ON : FocusMode::FOCUS_MODE_OFF
7177
);
7278

79+
$this->eventDispatcher->dispatch(new FocusModeChangedEvent($data->isEnabled()));
80+
7381
return $this->createRedirectToReturnPath($request);
7482
}
7583

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa 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 Ibexa\Contracts\AdminUi\Event;
10+
11+
use Symfony\Contracts\EventDispatcher\Event;
12+
13+
final class FocusModeChangedEvent extends Event
14+
{
15+
private bool $enabled;
16+
17+
public function __construct(bool $enabled)
18+
{
19+
$this->enabled = $enabled;
20+
}
21+
22+
public function isEnabled(): bool
23+
{
24+
return $this->enabled;
25+
}
26+
}

0 commit comments

Comments
 (0)