diff --git a/application/Espo/Core/Utils/Client/DevModeExtensionInitJsFileListProvider.php b/application/Espo/Core/Utils/Client/DevModeExtensionInitJsFileListProvider.php new file mode 100644 index 0000000000..a3a0ab625e --- /dev/null +++ b/application/Espo/Core/Utils/Client/DevModeExtensionInitJsFileListProvider.php @@ -0,0 +1,91 @@ +. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU Affero General Public License version 3. + * + * In accordance with Section 7(b) of the GNU Affero General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +namespace Espo\Core\Utils\Client; + +use Espo\Core\Utils\Config; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Module; +use Espo\Core\Utils\Util; + +/** + * Allows bundled extensions to work when the system is in the developer mode. + */ +class DevModeExtensionInitJsFileListProvider +{ + public function __construct( + private Module $module, + private FileManager $fileManager, + private Config $config, + ) {} + + /** + * @return string[] + */ + public function get(): array + { + $developedModule = $this->config->get('developedModule'); + + if (!$developedModule) { + return []; + } + + $output = []; + + foreach ($this->getBundledModuleList() as $module) { + if ($module === $developedModule) { + continue; + } + + $file = "client/custom/modules/$module/lib/init.js"; + + if ($this->fileManager->exists($file)) { + $output[] = $file; + } + } + + return $output; + } + + /** + * @return string[] + */ + private function getBundledModuleList(): array + { + $modules = array_values(array_filter( + $this->module->getList(), + fn ($item) => $this->module->get([$item, 'bundled']) + )); + + return array_map( + fn ($item) => Util::fromCamelCase($item, '-'), + $modules + ); + } +} diff --git a/application/Espo/Core/Utils/ClientManager.php b/application/Espo/Core/Utils/ClientManager.php index 7e92b2cd24..ae7bedca64 100644 --- a/application/Espo/Core/Utils/ClientManager.php +++ b/application/Espo/Core/Utils/ClientManager.php @@ -31,6 +31,7 @@ namespace Espo\Core\Utils; use Espo\Core\Api\Response; use Espo\Core\Api\ResponseWrapper; +use Espo\Core\Utils\Client\DevModeExtensionInitJsFileListProvider; use Espo\Core\Utils\Client\DevModeJsFileListProvider; use Espo\Core\Utils\Client\LoaderParamsProvider; use Espo\Core\Utils\Client\RenderParams; @@ -67,6 +68,7 @@ class ClientManager private Metadata $metadata, private FileManager $fileManager, private DevModeJsFileListProvider $devModeJsFileListProvider, + private DevModeExtensionInitJsFileListProvider $devModeExtensionInitJsFileListProvider, private Module $module, private LoaderParamsProvider $loaderParamsProvider, private SystemConfig $systemConfig, @@ -304,6 +306,7 @@ class ClientManager return array_merge( $this->metadata->get(['app', 'client', 'developerModeScriptList']) ?? [], $this->getDeveloperModeBundleLibFileList(), + $this->devModeExtensionInitJsFileListProvider->get(), ); }