Skip to content

Commit

Permalink
Add module style option for Layout Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Nov 9, 2023
1 parent 1ab1804 commit 7debfa5
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 92 deletions.
2 changes: 1 addition & 1 deletion assets/vendor/manager/dist/index.html

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions assets/vendor/manager/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/vendor/manager/index.html

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion assets/vendor/manager/src/components/helpers/Fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ function updateContentLayout() {
<select v-else-if="props.field.input.type === `astroidlist`" v-model="props.scope[props.field.name]" :id="props.field.input.id" :name="props.field.input.name" class="astroid-list form-select" :aria-label="props.field.label">
<option v-for="option in props.field.input.options" :key="option.value" :value="option.value">{{ option.text }}</option>
</select>
<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-select form-select" :aria-label="props.field.label">
<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 === `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>
<select v-else-if="props.field.input.type === `astroidanimations`" v-model="props.scope[props.field.name]" :id="props.field.input.id" :name="props.field.input.name" class="astroid-list form-select" :aria-label="props.field.label">
<option v-for="option in props.field.input.options" :key="option.value" :value="option.value">{{ option.text }}</option>
</select>
Expand Down
3 changes: 2 additions & 1 deletion framework/elements/module_position/module_position.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
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="astroidxhtml" />';
echo '<jdoc:include type="modules" name="' . $position . '" style="'.$module_styles.'" />';
}
echo Astroid\Framework::getDocument()->_positionContent($position, 'after');
3 changes: 2 additions & 1 deletion framework/elements/module_position/module_position.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<form>
<fields>
<fieldset name="general-settings" label="TPL_ASTROID_GENERAL_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field name="position" type="astroidmodulesposition" class="form-control" label="TPL_ASTROID_MODULE_POSITION_LABEL"></field>
<field name="position" type="astroidmodulesposition" label="TPL_ASTROID_MODULE_POSITION_LABEL"/>
<field name="module_styles" type="astroidmodulesstyle" label="TPL_ASTROID_MODULE_STYLE_LABEL"/>
</fieldset>
</fields>
</form>
Expand Down
71 changes: 0 additions & 71 deletions framework/fields/astroidmodulesposition.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Modules\Administrator\Helper\ModulesHelper;
use Joomla\CMS\Language\Text;
//JLoader::register('ModulesHelper', JPATH_ADMINISTRATOR . '/components/com_modules/helpers/modules.php');
FormHelper::loadFieldClass('list');

/**
Expand Down Expand Up @@ -56,81 +55,11 @@ public function getOptions()
return array_unique($positions);
}

protected function getLayoutData()
{
$data = parent::getLayoutData();
$extraData = array(
'ngShow' => $this->element['ngShow'],
'ngHide' => $this->element['ngHide'],
'ngModel' => $this->element['ngModel'],
'ngRequired' => $this->element['ngRequired'],
);
return array_merge($data, $extraData);
}

protected function getInput()
{
// $html = array();
$attr = '';

// Initialize some field attributes.
$attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
$attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
$attr .= $this->multiple ? ' multiple' : '';
$attr .= $this->required ? ' required aria-required="true"' : '';
$attr .= $this->autofocus ? ' autofocus' : '';
$attr .= ' ng-model="' . $this->fieldname . '"';
$attr .= ' data-fieldname="' . $this->fieldname . '"';
$attr .= $this->element['ngRequired'] ? ' ng-required="' . Astroid\Helper::replaceRelationshipOperators($this->element['ngRequired']) . '"' : '';

if (isset($this->element['astroid-content-layout']) && !empty($this->element['astroid-content-layout'])) {
$attr .= ' data-astroid-content-layout="' . $this->element['astroid-content-layout'] . '"';
}

if (isset($this->element['astroid-content-layout-load']) && !empty($this->element['astroid-content-layout-load'])) {
$attr .= ' data-astroid-content-layout-load="' . $this->element['astroid-content-layout-load'] . '"';
}

// To avoid user's confusion, readonly="true" should imply disabled="true".
if ((string) $this->readonly == '1' || (string) $this->readonly == 'true' || (string) $this->disabled == '1' || (string) $this->disabled == 'true') {
$attr .= ' disabled="disabled"';
}

// Initialize JavaScript field attributes.
$attr .= $this->onchange ? ' onchange="' . $this->onchange . '"' : '';

if (isset($this->element['astroid-animation-selector']) && $this->element['astroid-animation-selector'] == true) {
$attr .= ' animation-selector';
} else {
$attr .= ' select-ui-addable';
}

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

// // Create a read-only list (no name) with hidden input(s) to store the value(s).
// if ((string) $this->readonly == '1' || (string) $this->readonly == 'true') {
// $html[] = JHtml::_('select.genericlist', $options, '', trim($attr), 'value', 'text', $this->value, $this->id);
//
// // E.g. form field type tag sends $this->value as array
// if ($this->multiple && is_array($this->value)) {
// if (!count($this->value)) {
// $this->value[] = '';
// }
//
// foreach ($this->value as $value) {
// $html[] = '<input type="hidden" name="' . $this->name . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"/>';
// }
// } else {
// $html[] = '<input type="hidden" name="' . $this->name . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"/>';
// }
// } else {
// // Create a regular list.
// $html[] = JHtml::_('select.genericlist', $options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id);
// }
//
// return implode($html);

$json = [
'id' => $this->id,
'name' => $this->name,
Expand Down
52 changes: 52 additions & 0 deletions framework/fields/astroidmodulesstyle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* @package Astroid Framework
* @author Astroid Framework Team https://astroidframe.work
* @copyright Copyright (C) 2023 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\Component\Modules\Administrator\Helper\ModulesHelper;
use Joomla\CMS\Language\Text;
FormHelper::loadFieldClass('list');

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

/**
* The form field type.
*
* @var string
* @since 3.4.2
*/
protected $type = 'AstroidModulesStyle';
protected $ordering;
protected function getInput()
{
// Get the field options.
$options = Astroid\Helper::getModuleStyles();
if ($this->value) {
$value = $this->value;
} else {
$value = 'astroidxhtml';
}

$json = [
'id' => $this->id,
'name' => $this->name,
'value' => $value,
'options' => $options,
'type' => strtolower($this->type),
];
return json_encode($json);
}
}
51 changes: 51 additions & 0 deletions framework/layouts/chromes/astroidxhtml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @package Astroid Framework
* @author Astroid Framework https://astroidframe.work
* @copyright Copyright (C) 2023 AstroidFrame.work.
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;

$module = $displayData['module'];
$params = $displayData['params'];
$attribs = $displayData['attribs'];

if ($module->content === null || $module->content === '') {
return;
}

$moduleTag = $params->get('module_tag', 'div');
$moduleAttribs = [];
$moduleAttribs['class'] = $module->position . ' moduletable ' . htmlspecialchars($params->get('moduleclass_sfx', ''), ENT_QUOTES, 'UTF-8');
$headerTag = htmlspecialchars($params->get('header_tag', 'h3'), ENT_QUOTES, 'UTF-8');
$headerClass = htmlspecialchars($params->get('header_class', ''), ENT_QUOTES, 'UTF-8');
$headerAttribs = [];

// Only output a header class if one is set
if ($headerClass !== '') {
$headerAttribs['class'] = $headerClass;
}

// Only add aria if the moduleTag is not a div
if ($moduleTag !== 'div') {
if ($module->showtitle) :
$moduleAttribs['aria-labelledby'] = 'mod-' . $module->id;
$headerAttribs['id'] = 'mod-' . $module->id;
else :
$moduleAttribs['aria-label'] = $module->title;
endif;
}

$header = '<' . $headerTag . ' ' . ArrayHelper::toString($headerAttribs) . '>' . $module->title . '</' . $headerTag . '>';
?>
<<?php echo $moduleTag; ?> <?php echo ArrayHelper::toString($moduleAttribs); ?>>
<?php if ($module->showtitle) : ?>
<?php echo $header; ?>
<?php endif; ?>
<?php echo $module->content; ?>
</<?php echo $moduleTag; ?>>
21 changes: 21 additions & 0 deletions framework/library/astroid/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Joomla\CMS\Cache\CacheControllerFactoryInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Filesystem\Folder;
use Joomla\Registry\Registry;
use Joomla\CMS\Version;
use Joomla\CMS\Router\Route;
Expand Down Expand Up @@ -369,6 +370,26 @@ public static function getPositions()
return $positions;
}

public static function getModuleStyles()
{
$template = Framework::getTemplate();
$styles = Folder::files(\JPATH_SITE . '/templates/' . $template->template . '/html/layouts/chromes', '.php');
$options = array();
if (count($styles)) {
foreach ($styles as $style) {
$tmp = new \stdClass();
$tmp->value = basename($style,".php");
$tmp->text = basename($style,".php");
$options[] = $tmp;
}
}
$tmp = new \stdClass();
$tmp->value = 'none';
$tmp->text = 'none';
$options[] = $tmp;
return $options;
}

public static function frameworkVersion()
{
Framework::getDebugger()->log('Getting Framework Version');
Expand Down
1 change: 1 addition & 0 deletions language/en-GB/en-GB.astroid.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ASTROID_MINUTES="Minutes"
ASTROID_SECONDS="Seconds"
TPL_ASTROID_CONTAINER="Container"
TPL_ASTROID_MODULE_POSITION_LABEL="Module Position"
TPL_ASTROID_MODULE_STYLE_LABEL="Module Style"
TPL_ASTROID_HORIZONTAL="Horizontal"
TPL_ASTROID_STACKED="Stacked"
TPL_ASTROID_SIDEBAR="Sidebar"
Expand Down

0 comments on commit 7debfa5

Please sign in to comment.