Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module system improvements: Container modules #4794

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/Module/ModuleContainerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* webtrees: online genealogy
* Copyright (C) 2023 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace Fisharebest\Webtrees\Module;

use Illuminate\Support\Collection;

/**
* Interface ModuleCustomInterface - Classes and libraries for module system
*/
interface ModuleContainerInterface extends ModuleCustomInterface
{
/**
* The list of modules contained within this module.
*
* @return Collection<ModuleCustomInterface>
*/
public function containedModules(): Collection;
}
38 changes: 38 additions & 0 deletions app/Module/ModuleContainerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* webtrees: online genealogy
* Copyright (C) 2023 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace Fisharebest\Webtrees\Module;

use Illuminate\Support\Collection;

/**
* Trait ModuleContainerTrait - default implementation of ModuleCustomInterface
*/
trait ModuleContainerTrait
{
/**
* The list of modules contained within this module.
*
* @return Collection<ModuleCustomInterface>
*/
public function containedModules(): Collection
{
return new Collection();
}
}
25 changes: 20 additions & 5 deletions app/Services/ModuleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
use Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
use Fisharebest\Webtrees\Module\ModuleBlockInterface;
use Fisharebest\Webtrees\Module\ModuleChartInterface;
use Fisharebest\Webtrees\Module\ModuleContainerInterface;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleDataFixInterface;
use Fisharebest\Webtrees\Module\ModuleFooterInterface;
Expand Down Expand Up @@ -703,16 +704,30 @@ private function customModules(): Collection

return strlen($module_name) <= 30;
})
->map(static function (string $filename): ?ModuleCustomInterface {
->flatMap(static function (string $filename): Collection {
$module = self::load($filename);

if ($module instanceof ModuleCustomInterface) {
$module->setName('_' . basename(dirname($filename)) . '_');

return $module;
$moduleName = '_' . basename(dirname($filename)) . '_';
$module->setName($moduleName);

if ($module instanceof ModuleContainerInterface) {
$collection = $module->containedModules()
//force numeric keys
->values();

$collection->each(function (ModuleCustomInterface $submodule, int $key) use ($moduleName) {
$submodule->setName($moduleName . $key);
});

$collection->prepend($module);
return $collection;
}

return new Collection([$module]);
}

return null;
return new Collection();
})
->filter()
->mapWithKeys(static function (ModuleCustomInterface $module): array {
Expand Down