From b86d46f6f8e2fc9fe6166b68d1a6729d3bfb453e Mon Sep 17 00:00:00 2001 From: Helmut Kaufmann Date: Wed, 11 Feb 2026 19:33:26 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20register=20the=20event=20early,=20but=20?= =?UTF-8?q?don=E2=80=99t=20instantiate=20BlockManager=20early?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the Blocks plugin so the event listener is attached in register(), but BlockManager::instance() is only called later (inside the listener or in boot()). --- Plugin.php | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/Plugin.php b/Plugin.php index 950bb64..cb866e7 100644 --- a/Plugin.php +++ b/Plugin.php @@ -102,39 +102,37 @@ function (array $context, array $blocks) { public function boot(): void { $this->registerAssets(); - $this->extendThemeDatasource(); $this->extendControlLibraryBlocks(); } - - /** - * Register asset bundles for compilation - */ - protected function registerAssets(): void - { - \System\Classes\CombineAssets::registerCallback(function ($combiner) { - $combiner->registerBundle('$/winter/blocks/formwidgets/blocks/assets/less/blocks.less'); - }); - } - + /** - * Extend the theme's datasource to include the BlocksDatasource for loading blocks from + * Register method, called when the plugin is first registered. */ - protected function extendThemeDatasource(): void + public function register(): void { - // Register the block manager instance - BlockManager::instance(); Event::listen('cms.theme.registerHalcyonDatasource', function (Theme $theme, $resolver) { + BlockManager::instance(); // moved here + $source = $theme->getDatasource(); if ($source instanceof AutoDatasource) { - /* @var AutoDatasource $source */ $source->appendDatasource('blocks', new BlocksDatasource()); return; - } else { - $resolver->addDatasource($theme->getDirName(), new AutoDatasource([ - 'theme' => $source, - 'blocks' => new BlocksDatasource(), - ], 'blocks-autodatasource')); } + + $resolver->addDatasource($theme->getDirName(), new AutoDatasource([ + 'theme' => $source, + 'blocks' => new BlocksDatasource(), + ], 'blocks-autodatasource')); + }); + } + + /** + * Register asset bundles for compilation + */ + protected function registerAssets(): void + { + \System\Classes\CombineAssets::registerCallback(function ($combiner) { + $combiner->registerBundle('$/winter/blocks/formwidgets/blocks/assets/less/blocks.less'); }); }