Skip to content

Commit

Permalink
Add option load single module on Module element
Browse files Browse the repository at this point in the history
sonvnn committed Nov 27, 2024
1 parent 92babda commit 61c8558
Showing 7 changed files with 126 additions and 35 deletions.
2 changes: 1 addition & 1 deletion assets/vendor/manager/dist/index.html

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions assets/vendor/manager/dist/index.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions assets/vendor/manager/src/components/helpers/Fields.vue
Original file line number Diff line number Diff line change
@@ -90,6 +90,9 @@ function updateSubLayouts() {
<select v-else-if="props.field.input.type === `astroidmodulesposition`" v-model="props.scope[props.field.name]" :id="props.field.input.id" :name="props.field.input.name" class="astroid-module-position form-select" :aria-label="props.field.label">
<option v-for="(option, key) in props.field.input.options" :key="key" :value="key">{{ option }}</option>
</select>
<select v-else-if="props.field.input.type === `astroidmoduleslist`" v-model="props.scope[props.field.name]" :id="props.field.input.id" :name="props.field.input.name" class="astroid-module-list form-select" :aria-label="props.field.label">
<option v-for="(option, key) in props.field.input.options" :key="key" :value="option.id">{{ option.title }}</option>
</select>
<select v-else-if="props.field.input.type === `astroidmodulesstyle`" v-model="props.scope[props.field.name]" :id="props.field.input.id" :name="props.field.input.name" class="astroid-module-style form-select" :aria-label="props.field.label">
<option v-for="(option, key) in props.field.input.options" :key="key" :value="option.value">{{ option.text }}</option>
</select>
35 changes: 21 additions & 14 deletions framework/elements/module_position/module_position.php
Original file line number Diff line number Diff line change
@@ -3,27 +3,34 @@
/**
* @package Astroid Framework
* @author Astroid Framework Team https://astroidframe.work
* @copyright Copyright (C) 2023 AstroidFrame.work.
* @copyright Copyright (C) 2024 AstroidFrame.work.
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
* DO NOT MODIFY THIS FILE DIRECTLY AS IT WILL BE OVERWRITTEN IN THE NEXT UPDATE
* You can easily override all files under /astroid/ folder.
* Just copy the file to JROOT/media/templates/site/{YOUR_TEMPLATE_NAME}/astroid/elements/module_position/module_position.php folder to create and override
* See https://docs.joomdev.com/article/override-core-layouts/ for documentation
*/

use Joomla\CMS\Helper\ModuleHelper;
// No direct access.
defined('_JEXEC') or die;
extract($displayData);
$position = $params->get('position', '');
$module_styles = $params->get('module_styles', 'astroidxhtml');
if (empty($position)) {
return;
}

echo Astroid\Framework::getDocument()->_positionContent($position, 'before');
$modules = ModuleHelper::getModules($position);
if (count($modules)) {
echo '<jdoc:include type="modules" name="' . $position . '" style="'.$module_styles.'" />';
}
echo Astroid\Framework::getDocument()->_positionContent($position, 'after');
$type = $params->get('type', '');
if ($type == 'module') {
$moduleid = $params->get('module', 0);
if (!empty($moduleid)) {
$document = Astroid\Framework::getDocument();
echo $document->loadModule("{loadmoduleid $moduleid}");
}
} else {
$position = $params->get('position', '');
$module_styles = $params->get('module_styles', 'astroidxhtml');
if (empty($position)) {
return;
}
echo Astroid\Framework::getDocument()->_positionContent($position, 'before');
$modules = ModuleHelper::getModules($position);
if (count($modules)) {
echo '<jdoc:include type="modules" name="' . $position . '" style="'.$module_styles.'" />';
}
echo Astroid\Framework::getDocument()->_positionContent($position, 'after');
}
7 changes: 6 additions & 1 deletion framework/elements/module_position/module_position.xml
Original file line number Diff line number Diff line change
@@ -9,7 +9,12 @@
<form>
<fields>
<fieldset name="general-settings" label="TPL_ASTROID_GENERAL_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field astroidgroup="general" name="position" type="astroidmodulesposition" label="TPL_ASTROID_MODULE_POSITION_LABEL"/>
<field astroidgroup="general" type="astroidlist" name="type" label="TPL_ASTROID_PRELOADER_TYPE" default="">
<option value="">ASTROID_POSITION</option>
<option value="module">ASTROID_MODULE</option>
</field>
<field astroidgroup="general" ngShow="[type]==''" name="position" type="astroidmodulesposition" label="ASTROID_POSITION"/>
<field astroidgroup="general" ngShow="[type]=='module'" name="module" type="astroidmoduleslist" label="ASTROID_MODULE"/>
<field astroidgroup="general" name="module_styles" type="astroidmodulesstyle" label="TPL_ASTROID_MODULE_STYLE_LABEL"/>
</fieldset>
</fields>
76 changes: 76 additions & 0 deletions framework/fields/astroidmoduleslist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* @package Astroid Framework
* @author Astroid Framework Team https://astroidframe.work
* @copyright Copyright (C) 2024 AstroidFrame.work.
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
defined('JPATH_BASE') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Form\Field\ListField;
use Joomla\Database\DatabaseInterface;
use Joomla\CMS\Language\Text;
FormHelper::loadFieldClass('list');

/**
* Modules Position field.
*
* @since 3.4.2
*/
class JFormFieldAstroidModulesList extends ListField
{

/**
* The form field type.
*
* @var string
* @since 3.4.2
*/
protected $type = 'AstroidModulesList';
protected $ordering;

/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.4.2
*/
public function getOptions()
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->getQuery(true);
$extension = (string)$this->element['extension'];
if ($extension) {
$query->select('m.id, m.title')
->from('#__modules AS m')
->where('m.module' . ' = ' . $db->quote($extension))
->where('m.published' . ' = 1')
->where('m.client_id' . ' = 0');
} else {
$query->select('m.id, m.title')
->from('#__modules AS m')
->where('m.published' . ' = 1')
->where('m.client_id' . ' = 0');
}

return $db->setQuery($query)->loadObjectList();
}

protected function getInput()
{
// Get the field options.
$options = (array) $this->getOptions();

$json = [
'id' => $this->id,
'name' => $this->name,
'value' => htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'),
'options' => $options,
'type' => strtolower($this->type),
];
return json_encode($json);
}
}
2 changes: 1 addition & 1 deletion framework/library/astroid/Document.php
Original file line number Diff line number Diff line change
@@ -618,7 +618,7 @@ private function _modulePosition($position): false|string
private function _moduleId($id): false|string
{
$this->modules[$id] = '';
$document = Factory::getDocument();
$document = Factory::getApplication()->getDocument();
$renderer = $document->loadRenderer('module');
$modules = ModuleHelper::getModuleById($id);
ob_start();

0 comments on commit 61c8558

Please sign in to comment.