Skip to content

Commit cacd283

Browse files
committed
!410 - add create widgets.php file in component directory.
1 parent fe0a6ca commit cacd283

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

apps/Core/Packages/Devtools/Modules/DevtoolsModules.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
"NAMESPACE";
4+
5+
use System\Base\Providers\ModulesServiceProvider\Modules\Components\ComponentsWidgets;
6+
7+
class Widgets extends ComponentsWidgets
8+
{
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public function "WIDGETNAME"($widget, $dashboardWidget)
2+
{
3+
return $this->getWidgetContent($widget, $dashboardWidget);
4+
}

0 commit comments

Comments
 (0)