Skip to content

Commit

Permalink
Fix issue create custom Widget #707
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Jun 20, 2024
1 parent 955a83d commit 5aca217
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
12 changes: 9 additions & 3 deletions framework/library/astroid/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function getLayouts()
{
$app = Factory::getApplication();
$template_name = $app->input->get('template', NULL, 'RAW');
$this->response(Layout::getSublayouts($template_name));
$this->response(Layout::getDatalayouts($template_name, 'layouts'));
}

protected function getLayout()
Expand All @@ -87,7 +87,7 @@ protected function getLayout()
$template_name = $app->input->get('template', NULL, 'RAW');
$filename = $app->input->get('name', NULL, 'RAW');

$this->response(Layout::getSubLayout($filename, $template_name));
$this->response(Layout::getDataLayout($filename, $template_name, 'layouts'));
} catch (\Exception $e) {
$this->errorResponse($e);
}
Expand Down Expand Up @@ -154,13 +154,19 @@ protected function deleteLayouts()
$template_name = $app->input->get('template', NULL, 'RAW');
$layouts = $app->input->get('layouts', array(), 'RAW');

$this->response(Layout::deleteSublayouts($layouts, $template_name));
$this->response(Layout::deleteDatalayouts($layouts, $template_name, 'layouts'));
} catch (\Exception $e) {
$this->errorResponse($e);
}
return true;
}

protected function getArticleLayouts() {
$app = Factory::getApplication();
$template_name = $app->input->get('template', NULL, 'RAW');
$this->response(Layout::getDatalayouts($template_name, 'article_layouts'));
}

protected function getcategories()
{
$this->response(Utility::getCategories());
Expand Down
2 changes: 1 addition & 1 deletion framework/library/astroid/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct($type = '', $data = [], $template = null)
$this->template->setLog("Initiated Element : " . $type, "success");
if ($type !== 'subform') {
$library_elements_directory = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'framework' . '/' . 'elements' . '/';
$template_elements_directory = JPATH_SITE . '/' . 'templates' . '/' . $this->template->template . '/' . 'astroid' . '/' . 'elements' . '/';
$template_elements_directory = JPATH_SITE . '/media/templates/site/' . $this->template->template . '/' . 'astroid' . '/' . 'elements' . '/';

switch ($this->type) {
case 'section':
Expand Down
18 changes: 9 additions & 9 deletions framework/library/astroid/Element/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function render()
public static function renderSublayout($source, $template = '')
{
Framework::getDebugger()->log('Render '.$source.' Layout');
$sublayout = self::getSubLayout($source, $template);
$sublayout = self::getDataLayout($source, $template, 'layouts');
if (!isset($sublayout['data']) || !$sublayout['data']) {
return '';
}
Expand All @@ -63,13 +63,13 @@ public static function renderSublayout($source, $template = '')
return $content;
}

public static function getSublayouts($template = '')
public static function getDatalayouts($template = '', $type = '')
{
if (!$template) {
$template = Framework::getTemplate()->template;
}

$layouts_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/layouts/";
$layouts_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/{$type}/";
if (!file_exists($layouts_path)) {
return [];
}
Expand All @@ -86,14 +86,14 @@ public static function getSublayouts($template = '')
$layout['desc'] = Text::_($data['desc']);
}
if (isset($data['thumbnail']) && !empty($data['thumbnail'])) {
$layout['thumbnail'] = Uri::root() . 'media/templates/site/' . $template . '/images/layouts/' . $data['thumbnail'];
$layout['thumbnail'] = Uri::root() . 'media/templates/site/' . $template . '/images/' . $type . '/' . $data['thumbnail'];
}
$layouts[] = $layout;
}
return $layouts;
}

public static function getSubLayout($filename = '', $template = '')
public static function getDataLayout($filename = '', $template = '', $type = '')
{
if (!$filename) {
return [];
Expand All @@ -102,7 +102,7 @@ public static function getSubLayout($filename = '', $template = '')
$template = Framework::getTemplate()->template;
}

$layout_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/layouts/" . $filename . '.json';
$layout_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/{$type}/" . $filename . '.json';
if (!file_exists($layout_path)) {
return [];
}
Expand All @@ -112,7 +112,7 @@ public static function getSubLayout($filename = '', $template = '')
return $data;
}

public static function deleteSublayouts($layouts = [], $template = '')
public static function deleteDatalayouts($layouts = [], $template = '', $type = '')
{
if (!count($layouts)) {
return false;
Expand All @@ -121,8 +121,8 @@ public static function deleteSublayouts($layouts = [], $template = '')
$template = Framework::getTemplate()->template;
}

$layouts_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/layouts/";
$images_path = JPATH_SITE . "/media/templates/site/{$template}/images/layouts/";
$layouts_path = JPATH_SITE . "/media/templates/site/{$template}/astroid/{$type}/";
$images_path = JPATH_SITE . "/media/templates/site/{$template}/images/{$type}/";
foreach ($layouts as $layout) {
if (file_exists($layouts_path . $layout . '.json')) {
$json = file_get_contents($layouts_path . $layout . '.json');
Expand Down

0 comments on commit 5aca217

Please sign in to comment.