Skip to content

Commit

Permalink
Fix issue can't read template_name in Article Layout Form
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Jul 16, 2024
1 parent 7cf85a4 commit 2c03cf5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
2 changes: 1 addition & 1 deletion assets/vendor/articlelayout/dist/index.js

Large diffs are not rendered by default.

43 changes: 32 additions & 11 deletions framework/library/astroid/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\Filesystem\Folder;
use Joomla\Filesystem\Path;

defined('_JEXEC') or die;

class Element
Expand Down Expand Up @@ -58,11 +61,17 @@ public function __construct($type = '', $data = [], $template = null, $mode = ''
$this->template = $template;
}

$template_name = $this->template->isAstroid ? $this->template->template : '';
if (empty($template_name) && defined('ASTROID_TEMPLATE_NAME')) {
$template_name = ASTROID_TEMPLATE_NAME;
}

$this->setClassName();
$this->template->setLog("Initiated Element : " . $type, "success");
if ($type !== 'subform') {
$library_elements_directory = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'framework' . '/' . 'elements' . '/';
$template_elements_directory = JPATH_SITE . '/media/templates/site/' . $this->template->template . '/' . 'astroid' . '/' . 'elements' . '/';
if ($type !== 'subform' && $type !=='sublayout') {
$library_elements_directory = Path::clean(JPATH_LIBRARIES . '/astroid/framework/elements/');
$plugin_elements_directory = Path::clean(JPATH_SITE . '/plugins/astroid/');
$template_elements_directory = Path::clean(JPATH_SITE . '/media/templates/site/' . $template_name . '/astroid/elements/');

switch ($this->type) {
case 'section':
Expand All @@ -74,8 +83,6 @@ public function __construct($type = '', $data = [], $template = null, $mode = ''
case 'row':
$this->default_xml_file = $library_elements_directory . 'row-default.xml';
break;
case 'sublayout':
break;
default:
if (file_exists($library_elements_directory . $this->type . '/default.xml')) {
$this->default_xml_file = $library_elements_directory . $this->type . '/default.xml';
Expand All @@ -87,12 +94,26 @@ public function __construct($type = '', $data = [], $template = null, $mode = ''
break;
}

if (file_exists($template_elements_directory . $this->type . '/' . $this->type . '.xml')) {
$this->xml_file = $template_elements_directory . $this->type . '/' . $this->type . '.xml';
$this->layout = $template_elements_directory . $this->type . '/' . $this->type . '.php';
} else if (file_exists($library_elements_directory . $this->type . '/' . $this->type . '.xml')) {
$this->xml_file = $library_elements_directory . $this->type . '/' . $this->type . '.xml';
$this->layout = $library_elements_directory . $this->type . '/' . $this->type . '.php';
if (file_exists(Path::clean($library_elements_directory . $this->type . '/' . $this->type . '.xml'))) {
$this->xml_file = Path::clean($library_elements_directory . $this->type . '/' . $this->type . '.xml');
$this->layout = Path::clean($library_elements_directory . $this->type . '/' . $this->type . '.php');
}

if (file_exists($plugin_elements_directory)) {
$plugin_folders = Folder::folders($plugin_elements_directory);
if (count($plugin_folders)) {
foreach ($plugin_folders as $plugin_folder) {
if (file_exists(Path::clean($plugin_elements_directory . '/' . $plugin_folder . '/elements/' . $this->type . '/' . $this->type . '.xml'))) {
$this->xml_file = Path::clean($plugin_elements_directory . '/' . $plugin_folder . '/elements/' . $this->type . '/' . $this->type . '.xml');
$this->layout = Path::clean($plugin_elements_directory . '/' . $plugin_folder . '/elements/' . $this->type . '/' . $this->type . '.php');
}
}
}
}

if (file_exists(Path::clean($template_elements_directory . $this->type . '/' . $this->type . '.xml'))) {
$this->xml_file = Path::clean($template_elements_directory . $this->type . '/' . $this->type . '.xml');
$this->layout = Path::clean($template_elements_directory . $this->type . '/' . $this->type . '.php');
}
}

Expand Down
7 changes: 4 additions & 3 deletions framework/library/astroid/Element/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Astroid\Helper;
use Joomla\CMS\Factory;
use Joomla\CMS\Layout\FileLayout;
use Joomla\Filesystem\Path;

defined('_JEXEC') or die;

Expand Down Expand Up @@ -46,9 +47,9 @@ public function _content()
$id = $app->input->get('id', null, 'RAW');
if ($option === 'com_content' && $view === 'article' && !empty($id)) {
$template_name = Framework::getTemplate()->template;
$layout_path = JPATH_SITE . "/media/templates/site/$template_name/astroid/article_widget_data/";
if (file_exists($layout_path . $id . '_' . $this->unqid . '.json')) {
$article_json = file_get_contents($layout_path . $id . '_' . $this->unqid . '.json');
$layout_path = Path::clean(JPATH_SITE . "/media/templates/site/$template_name/astroid/article_widget_data/". $id . '_' . $this->unqid . '.json');
if (file_exists($layout_path)) {
$article_json = file_get_contents($layout_path);
$article_data = json_decode($article_json, true);
$article_params = Helper::loadParams($article_data['params']);
$this->params->merge($article_params);
Expand Down
19 changes: 13 additions & 6 deletions framework/library/astroid/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,17 @@ public static function getModules()
public static function getAllAstroidElements($mode = '', $template_id = null)
{
$template = Framework::getTemplate($template_id);
$template_name = '';
if ($template->isAstroid) {
$template_name = $template->template;
} elseif (defined('ASTROID_TEMPLATE_NAME')) {
$template_name = ASTROID_TEMPLATE_NAME;
}

// Template Directories
$elements_dir = JPATH_LIBRARIES . '/astroid/framework/elements/';
$plugin_elements_dir = JPATH_SITE . "/plugins/astroid";
$template_elements_dir = JPATH_SITE . '/media/templates/site/' . $template->template . '/astroid/elements/';
$template_elements_dir = JPATH_SITE . '/media/templates/site/' . $template_name . '/astroid/elements/';

// Getting Elements from Template Directories
$elements = Folder::folders($elements_dir, '.', false, true);
Expand All @@ -355,10 +362,11 @@ public static function getAllAstroidElements($mode = '', $template_id = null)
}
}

$template_elements = Folder::folders($template_elements_dir, '.', false, true);

// Merging Elements
$elements = array_merge($elements, $template_elements);
if ($template_name && file_exists(Path::clean($template_elements_dir))) {
$template_elements = Folder::folders($template_elements_dir, '.', false, true);
// Merging Elements
$elements = array_merge($elements, $template_elements);
}

$return = array();

Expand All @@ -372,7 +380,6 @@ public static function getAllAstroidElements($mode = '', $template_id = null)

$type = substr($element_dir, $slash + 1);
$xmlfile = $element_dir . '/' . $type . '.xml';

if (file_exists($xmlfile)) {
$element = new Element($type, [], $template, $mode);
$return[] = $element;
Expand Down
4 changes: 4 additions & 0 deletions framework/library/astroid/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function __construct($id = 0)
$this->params = $jtemplate->params;
$this->title = '';

if (!empty($this->params->get('astroid', 0))) {
$this->isAstroid = true;
}

if (Framework::isSite()) {
$this->_set($jtemplate->id);
} else if (Framework::isAdmin()) {
Expand Down

0 comments on commit 2c03cf5

Please sign in to comment.