@@ -303,6 +303,7 @@ protected function updateModuleJson($data)
303303 $ jsonContent = str_replace ('\\" ' , '" ' , $ jsonContent );
304304 $ jsonContent = str_replace ('"{ ' , '{ ' , $ jsonContent );
305305 $ jsonContent = str_replace ('}" ' , '} ' , $ jsonContent );
306+ $ jsonContent = str_replace ('\\n ' , '' , $ jsonContent );
306307 $ jsonContent = $ this ->basepackages ->utils ->formatJson (['json ' => $ jsonContent ]);
307308
308309 try {
@@ -599,6 +600,46 @@ protected function generateNewComponentsFiles($moduleFilesLocation, $data)
599600 return false ;
600601 }
601602
603+ if (isset ($ data ['widgets ' ]) && $ data ['widgets ' ] !== '' ) {
604+ $ data ['widgets ' ] = Json::decode ($ data ['widgets ' ], true );
605+
606+ try {
607+ $ file = $ this ->localContent ->read ('apps/Core/Packages/Devtools/Modules/Files/ComponentWidget.txt ' );
608+ } catch (FilesystemException | UnableToReadFile $ exception ) {
609+ $ this ->addResponse ('Unable to read module base component file. ' );
610+
611+ return false ;
612+ }
613+
614+
615+ $ file = str_replace ('"NAMESPACE" ' , 'namespace ' . $ namespaceClass , $ file );
616+
617+ foreach ($ data ['widgets ' ] as $ widget ) {
618+ try {
619+ $ methodFile = $ this ->localContent ->read ('apps/Core/Packages/Devtools/Modules/Files/ComponentWidgetMethod.txt ' );
620+ } catch (FilesystemException | UnableToReadFile $ exception ) {
621+ $ this ->addResponse ('Unable to read module base component file. ' );
622+
623+ return false ;
624+ }
625+
626+ $ methodFile = str_replace ('"WIDGETNAME" ' , $ widget ['method ' ], $ methodFile );
627+
628+ $ file .= '
629+ ' . $ methodFile ;
630+ }
631+
632+ $ file .= '} ' ;
633+ }
634+
635+ try {
636+ $ this ->localContent ->write ($ moduleFilesLocation . 'Widgets.php ' , $ file );
637+ } catch (FilesystemException | UnableToWriteFile $ exception ) {
638+ $ this ->addResponse ('Unable to write module component file ' );
639+
640+ return false ;
641+ }
642+
602643 return true ;
603644 }
604645
0 commit comments