-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
- Loading branch information
1 parent
de1c175
commit 951d914
Showing
7 changed files
with
256 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Settings\Listener; | ||
|
||
use OCA\Settings\AppInfo\Application; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\IAppConfig; | ||
use OCP\Settings\Events\DeclarativeSettingsGetValueEvent; | ||
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent; | ||
|
||
/** @template-implements IEventListener<DeclarativeSettingsGetValueEvent|DeclarativeSettingsSetValueEvent> */ | ||
class MailProviderListener implements IEventListener { | ||
|
||
public function __construct( | ||
private IAppConfig $config, | ||
) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
|
||
/** @var DeclarativeSettingsGetValueEvent|DeclarativeSettingsSetValueEvent $event */ | ||
if ($event->getApp() !== Application::APP_ID) { | ||
return; | ||
} | ||
|
||
if ($event instanceof DeclarativeSettingsGetValueEvent) { | ||
$this->handleGetValue($event); | ||
return; | ||
} | ||
|
||
if ($event instanceof DeclarativeSettingsSetValueEvent) { | ||
$this->handleSetValue($event); | ||
return; | ||
} | ||
|
||
} | ||
|
||
private function handleGetValue(DeclarativeSettingsGetValueEvent $event): void { | ||
|
||
if ($event->getFieldId() === 'mail_providers_enabled') { | ||
$event->setValue((int)$this->config->getValueBool('core', 'mail_providers_enabled', true)); | ||
} | ||
|
||
} | ||
|
||
private function handleSetValue(DeclarativeSettingsSetValueEvent $event): void { | ||
|
||
if ($event->getFieldId() === 'mail_providers_enabled') { | ||
$this->config->setValueBool('core', 'mail_providers_enabled', (bool)$event->getValue()); | ||
$event->stopPropagation(); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.