diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-02-15 21:07:52 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-02-16 08:36:33 +0000 |
| commit | 888ddf4f75ad7e5e5b322ccfa329fb24ddc9af04 (patch) | |
| tree | 2c07bbd2bad3bf46a2b71ebda29c8090fb44e8a4 | |
| parent | 5553c41de7298482d2781f742a95f792be84e161 (diff) | |
| download | webtrees-888ddf4f75ad7e5e5b322ccfa329fb24ddc9af04.tar.gz webtrees-888ddf4f75ad7e5e5b322ccfa329fb24ddc9af04.tar.bz2 webtrees-888ddf4f75ad7e5e5b322ccfa329fb24ddc9af04.zip | |
Allow modules to be initially disabled
| -rw-r--r-- | app/Module/AbstractModule.php | 10 | ||||
| -rw-r--r-- | app/Module/ModuleInterface.php | 7 | ||||
| -rw-r--r-- | app/Services/ModuleService.php | 7 | ||||
| -rw-r--r-- | modules_v4/historic-events.example/module.php | 10 |
4 files changed, 33 insertions, 1 deletions
diff --git a/app/Module/AbstractModule.php b/app/Module/AbstractModule.php index a7ab520f96..c9ccde222b 100644 --- a/app/Module/AbstractModule.php +++ b/app/Module/AbstractModule.php @@ -159,6 +159,16 @@ abstract class AbstractModule implements ModuleInterface } /** + * Should this module be enabled when it is first installed? + * + * @return bool + */ + public function isEnabledByDefault(): bool + { + return true; + } + + /** * Get a module setting. Return a default if the setting is not set. * * @param string $setting_name diff --git a/app/Module/ModuleInterface.php b/app/Module/ModuleInterface.php index 25320ea2f9..3541501846 100644 --- a/app/Module/ModuleInterface.php +++ b/app/Module/ModuleInterface.php @@ -57,6 +57,13 @@ interface ModuleInterface public function isEnabled(): bool; /** + * Should this module be enabled when it is first installed? + * + * @return bool + */ + public function isEnabledByDefault(): bool; + + /** * How should this module be labelled on tabs, menus, etc.? * * @return string diff --git a/app/Services/ModuleService.php b/app/Services/ModuleService.php index 5dc9fc6786..7e71841dd5 100644 --- a/app/Services/ModuleService.php +++ b/app/Services/ModuleService.php @@ -347,7 +347,12 @@ class ModuleService $module->setTabOrder((int) $info->tab_order); } } else { - DB::table('module')->insert(['module_name' => $module->name()]); + $module->setEnabled($module->isEnabledByDefault()); + + DB::table('module')->insert([ + 'module_name' => $module->name(), + 'status' => $module->isEnabled() ? 'enabled' : 'disabled', + ]); } return $module; diff --git a/modules_v4/historic-events.example/module.php b/modules_v4/historic-events.example/module.php index da3607fbf0..82dbf74a05 100644 --- a/modules_v4/historic-events.example/module.php +++ b/modules_v4/historic-events.example/module.php @@ -22,6 +22,16 @@ return new class extends AbstractModule implements ModuleCustomInterface, Module } /** + * Should this module be enabled when it is first installed? + * + * @return bool + */ + public function isEnabledByDefault(): bool + { + return false; + } + + /** * All events provided by this module. * * @return string[] |
