Our Example is based on Clean Theme and we like to use our new abccore Module as the "hub" for our overall overriden files that we use in multiple modules.
Below is how the Clean Theme is wiring up its view overrides, and then a pattern you can borrow in your abccore module so that all of your future overrides live in one place under modules/abccore/views/overrides and never get stomped by a core update.
DynamicConfig rewrite When you enable the Clean Theme module, it calls
ThemeHelper::getThemeByName('Clean')->activate();
DynamicConfig::rewrite();
That writes into your protected/config/web.php something like:
'components' => [
'view' => [
'theme' => [
'basePath' => '@app/themes/Clean',
'baseUrl' => '@web/themes/Clean',
'pathMap' => [
'@humhub/modules' => '@app/themes/Clean/modules',
'@humhub/widgets' => '@app/themes/Clean/widgets',
'@humhub/views' => '@app/themes/Clean/views',
],
],
],
],
Mirror the folder structure
Inside themes/Clean you see directories like
themes/
Clean/
modules/
space/
views/
spaces/
index.php ← your override here
widgets/
topNavigation.php ← override HumHub widget views
views/
humhub/
layouts/
main.php ← override core layouts
Yii’s theme pathMap will look for the original view under @humhub/modules/space/views/spaces/index.php and, if it finds the file in your theme folder, load that instead.
Rather than scatter overrides across multiple modules (and fight path aliases), you can make abccore supply an “override root” that covers all HumHub view paths:
Create an override folder In your module add:
protected/modules/abccore/views/overrides/humhub/
modules/
widgets/
views/
Inside each of those sub‐folders you mirror only the directories you actually override. For example, to override the Spaces index:
views/overrides/humhub/modules/space/views/spaces/index.php
And for the SpaceDirectoryCard widget:
views/overrides/humhub/modules/space/widgets/views/spaceDirectoryCard.php
Wire up the pathMap
In protected/modules/abccore/Module.php implement bootstrap() and merge in a single mapping from @humhub → your override root. For example:
namespace abc\modules\abccore;
use Yii;
use yii\base\Module as BaseModule;
use yii\base\BootstrapInterface;
use yii\base\Theme;
class Module extends BaseModule implements BootstrapInterface
{
public function bootstrap($app)
{
parent::bootstrap($app);
$view = $app->getView();
if (!$view->theme) {
$view->theme = new Theme();
}
// Grab whatever was already there, then inject our override root
$pathMap = $view->theme->pathMap ?: [];
$pathMap['@humhub'] = [
__DIR__ . '/views/overrides/humhub'
];
$view->theme->pathMap = $pathMap;
}
}
This says “for any view under @humhub/..., look first in modules/abccore/views/overrides/humhub/... using the identical sub-path.”
Flush the cache After deploying, run:
./yii cache/flush-all
or use Admin → Settings → Cache.
Verify
Drop a <!-- OVERRIDE LOADED --> comment at the top of one of your override files (e.g. the Spaces index) to confirm it’s being picked up.
views/overrides/humhub) in your abccore module.@humhub lookup at your folder first, so core updates won’t touch your overrides.We can now retire the piecemeal “space-overrides” hack in our other modules and consolidate every view override into abccore/views/overrides/humhub, exactly the same way Clean-Theme centralizes its work under themes/Clean.