Skip to content

Commit

Permalink
Fix issue can not get article widget override data #889
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Nov 29, 2024
1 parent dc46595 commit b1f0395
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
10 changes: 8 additions & 2 deletions framework/elements/formbuilder/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Language\Text;
use Astroid\Helper;
use Astroid\Framework;

$mainframe = Factory::getApplication();
$asformbuilder = $mainframe->input->post->get('as-form-builder-', array(), 'RAW');
$unqid = $mainframe->input->post->get('form_id', '', 'string');
$source = $mainframe->input->post->get('source', '', 'string');
$template = $mainframe->input->post->get('template', '', 'string');
$template_id = $mainframe->input->post->get('template', '', 'ALNUM');
$template = Framework::getTemplate(intval($template_id));
$layout_type = $mainframe->input->post->get('layout_type', '', 'string');
$element = Helper::getElement($unqid, '', ['source' => $source, 'template' => $template, 'layout_type' => $layout_type]);
$article_id = 0;
if ($layout_type == 'article_layouts') {
$article_id = $mainframe->input->post->get('id', 0, 'int');
}
$element = Helper::getElement($unqid, '', ['source' => $source, 'template' => $template->template, 'layout_type' => $layout_type, 'article_id' => $article_id]);
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$return = array();
Expand Down
6 changes: 3 additions & 3 deletions framework/elements/formbuilder/formbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@
if (isset($options['source']) && $options['source']) {
echo '<input type="hidden" name="source" value="'.$options['source'].'">';
}
if (isset($options['template']) && $options['template']) {
echo '<input type="hidden" name="template" value="'.$options['template'].'">';
}
if (isset($options['layout_type']) && $options['layout_type']) {
echo '<input type="hidden" name="layout_type" value="'.$options['layout_type'].'">';
if ($options['layout_type'] == 'article_layouts') {
echo '<input type="hidden" name="id" value="'.$mainframe->input->get('id', 0, 'INT').'">';
}
}
echo '<input type="hidden" class="token" name="'.Session::getFormToken().'" value="1">';

Expand Down
1 change: 0 additions & 1 deletion framework/library/astroid/Element/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public static function renderSublayout($source, $template = '', $type = 'layouts
];
$options['layout_type'] = $type;
$options['source'] = $source;
$options['template'] = !empty($template) ? $template : Framework::getTemplate()->template;
$content = '';
foreach ($layout['sections'] as $section) {
$section = new Section($section, $devices, $options);
Expand Down
13 changes: 13 additions & 0 deletions framework/library/astroid/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,13 @@ public static function getElement($unqid, $template = null, $options = []) {
if (empty($template)) {
$template = Framework::getTemplate();
}
$layout_type = 'templates';
if (isset($options['source']) && !empty($options['source'])) {
$sublayout = Layout::getDataLayout($options['source'], (isset($options['template']) && !empty($options['template']) ? $options['template'] : ''), (isset($options['layout_type']) && !empty($options['layout_type']) ? $options['layout_type'] : 'layouts'));
if (!isset($sublayout['data']) || !$sublayout['data']) {
return false;
}
$layout_type = isset($options['layout_type']) && !empty($options['layout_type']) ? $options['layout_type'] : 'layouts';
$layout = \json_decode($sublayout['data'], true);
} else {
$layout = $template->getLayout();
Expand All @@ -435,6 +437,17 @@ public static function getElement($unqid, $template = null, $options = []) {
foreach ($col['elements'] as $element) {
if ($element['id'] == $unqid) {
$element['params'] = self::loadParams($element['params']);
if ($layout_type == 'article_layouts') {
$template_name = isset($options['template']) && !empty($options['template']) ? $options['template'] : $template->template;
$article_id = isset($options['article_id']) && !empty($options['article_id']) ? $options['article_id'] : 0;
$layout_path = Path::clean(JPATH_SITE . "/media/templates/site/$template_name/astroid/article_widget_data/". $article_id . '_' . $unqid . '.json');
if (file_exists($layout_path)) {
$article_json = file_get_contents($layout_path);
$article_data = json_decode($article_json, true);
$article_params = self::loadParams($article_data['params']);
$element['params']->merge($article_params);
}
}
return $element;
}
}
Expand Down

0 comments on commit b1f0395

Please sign in to comment.