Skip to content

Commit aa2acfd

Browse files
authored
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 4e970ba commit aa2acfd

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

phpstan-baseline.neon

Lines changed: 6 additions & 1 deletion
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
@@ -6556,7 +6561,7 @@ parameters:
65566561
path: src/lib/Form/Type/ContentType/ContentTypesDeleteType.php
65576562

65586563
-
6559-
message: "#^Parameter \\#1 \\$child of method Symfony\\\\Component\\\\Form\\\\FormBuilderInterface\\:\\:add\\(\\) expects string\\|Symfony\\\\Component\\\\Form\\\\FormBuilderInterface, int\\|string given\\.$#"
6564+
message: "#^Parameter \\#1 \\$child of method Symfony\\\\Component\\\\Form\\\\FormBuilderInterface\\<mixed\\>\\:\\:add\\(\\) expects string\\|Symfony\\\\Component\\\\Form\\\\FormBuilderInterface, int\\|string given\\.$#"
65606565
count: 1
65616566
path: src/lib/Form/Type/ContentType/FieldDefinitionsCollectionType.php
65626567

src/bundle/Controller/User/FocusModeController.php

Lines changed: 11 additions & 2 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;
@@ -21,10 +23,15 @@ final class FocusModeController extends Controller
2123
{
2224
private const RETURN_URL_PARAM = 'returnUrl';
2325

26+
private EventDispatcherInterface $eventDispatcher;
27+
2428
private UserSettingService $userSettingService;
2529

26-
public function __construct(UserSettingService $userSettingService)
27-
{
30+
public function __construct(
31+
EventDispatcherInterface $eventDispatcher,
32+
UserSettingService $userSettingService
33+
) {
34+
$this->eventDispatcher = $eventDispatcher;
2835
$this->userSettingService = $userSettingService;
2936
}
3037

@@ -54,6 +61,8 @@ public function changeAction(Request $request, ?string $returnUrl): Response
5461
$data->isEnabled() ? FocusMode::FOCUS_MODE_ON : FocusMode::FOCUS_MODE_OFF
5562
);
5663

64+
$this->eventDispatcher->dispatch(new FocusModeChangedEvent($data->isEnabled()));
65+
5766
return $this->createRedirectToReturnUrl($request);
5867
}
5968

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)