Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Show active module positions on Module element #72

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
83 changes: 67 additions & 16 deletions administrator/components/com_modules/Helper/ModulesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
*/

namespace Joomla\Component\Modules\Administrator\Helper;
Expand Down Expand Up @@ -32,7 +33,7 @@ abstract class ModulesHelper
public static function getStateOptions()
{
// Build the filter options.
$options = array();
$options = [];
$options[] = HTMLHelper::_('select.option', '1', Text::_('JPUBLISHED'));
$options[] = HTMLHelper::_('select.option', '0', Text::_('JUNPUBLISHED'));
$options[] = HTMLHelper::_('select.option', '-2', Text::_('JTRASHED'));
Expand All @@ -49,13 +50,62 @@ public static function getStateOptions()
public static function getClientOptions()
{
// Build the filter options.
$options = array();
$options = [];
$options[] = HTMLHelper::_('select.option', '0', Text::_('JSITE'));
$options[] = HTMLHelper::_('select.option', '1', Text::_('JADMINISTRATOR'));

return $options;
}

/**
* Get a list of modules positions which are defined / used in the pagebuilder
*
* @param int $clientId The client ID the template styles belong to
*
* @return array A list of positions
*
* @since 4.0.0
*/
public static function getLayoutBuilderPositions(int $clientId): array
{
$customPosNames = [];
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__template_styles'))
->where($db->quoteName('client_id') . ' = ' . $clientId);

$db->setQuery($query);

$list = $db->loadObjectList();

foreach ($list as $param)
{
$params = json_decode($param->params, true);

if ($params['grid'] ?? false)
{
$paramsGridConf = json_decode($params['grid'], true);

array_walk_recursive(
$paramsGridConf,
static function ($value, $key) use (&$customPosNames) {
if ($key === 'position_name')
{
$customPosNames[] = [
'value' => $value,
'text' => $value,
'disable' => false
];
}
}
);
}
}

return $customPosNames;
}

/**
* Get a list of modules positions
*
Expand Down Expand Up @@ -84,7 +134,8 @@ public static function getPositions($clientId, $editPositions = false)
}
catch (\RuntimeException $e)
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
Factory::getApplication()
->enqueueMessage($e->getMessage(), 'error');

return;
}
Expand Down Expand Up @@ -176,15 +227,15 @@ public static function getModules($clientId)

$db->setQuery($query);
$modules = $db->loadObjectList();
$lang = Factory::getLanguage();
$lang = Factory::getLanguage();

foreach ($modules as $i => $module)
{
$extension = $module->value;
$path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$source = $path . "/modules/$extension";
$lang->load("$extension.sys", $path, null, false, true)
|| $lang->load("$extension.sys", $source, null, false, true);
$path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$source = $path . "/modules/$extension";
$lang->load("$extension.sys", $path, null, false, true)
|| $lang->load("$extension.sys", $source, null, false, true);
$modules[$i]->text = Text::_($module->text);
}

Expand All @@ -202,7 +253,7 @@ public static function getModules($clientId)
*/
public static function getAssignmentOptions($clientId)
{
$options = array();
$options = array();
$options[] = HTMLHelper::_('select.option', '0', 'COM_MODULES_OPTION_MENU_ALL');
$options[] = HTMLHelper::_('select.option', '-', 'COM_MODULES_OPTION_MENU_NONE');

Expand Down Expand Up @@ -238,20 +289,20 @@ public static function getTranslatedModulePosition($clientId, $template, $positi
if (!$loaded)
{
$lang->load('tpl_' . $template . '.sys', $path, null, false, false)
|| $lang->load('tpl_' . $template . '.sys', $path . '/templates/' . $template, null, false, false)
|| $lang->load('tpl_' . $template . '.sys', $path, $lang->getDefault(), false, false)
|| $lang->load('tpl_' . $template . '.sys', $path . '/templates/' . $template, $lang->getDefault(), false, false);
|| $lang->load('tpl_' . $template . '.sys', $path . '/templates/' . $template, null, false, false)
|| $lang->load('tpl_' . $template . '.sys', $path, $lang->getDefault(), false, false)
|| $lang->load('tpl_' . $template . '.sys', $path . '/templates/' . $template, $lang->getDefault(), false, false);
}

$langKey = strtoupper('TPL_' . $template . '_POSITION_' . $position);
$text = Text::_($langKey);
$text = Text::_($langKey);

// Avoid untranslated strings
if (!self::isTranslatedText($langKey, $text))
{
// Modules component translation
$langKey = strtoupper('COM_MODULES_POSITION_' . $position);
$text = Text::_($langKey);
$text = Text::_($langKey);

// Avoid untranslated strings
if (!self::isTranslatedText($langKey, $text))
Expand Down Expand Up @@ -297,7 +348,7 @@ public static function createOption($value = '', $text = '')
$text = $value;
}

$option = new \stdClass;
$option = new \stdClass;
$option->value = $value;
$option->text = $text;

Expand All @@ -316,7 +367,7 @@ public static function createOption($value = '', $text = '')
*/
public static function createOptionGroup($label = '', $options = array())
{
$group = array();
$group = array();
$group['value'] = $label;
$group['text'] = $label;
$group['items'] = $options;
Expand Down
30 changes: 19 additions & 11 deletions administrator/components/com_modules/Service/HTML/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
*/

namespace Joomla\Component\Modules\Administrator\Service\HTML;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function templates($clientId = 0, $state = '')
*/
public function types()
{
$options = array();
$options = array();
$options[] = HTMLHelper::_('select.option', 'user', 'COM_MODULES_OPTION_POSITION_USER_DEFINED');
$options[] = HTMLHelper::_('select.option', 'template', 'COM_MODULES_OPTION_POSITION_TEMPLATE_DEFINED');

Expand All @@ -68,7 +69,7 @@ public function types()
*/
public function templateStates()
{
$options = array();
$options = array();
$options[] = HTMLHelper::_('select.option', '1', 'JENABLED');
$options[] = HTMLHelper::_('select.option', '0', 'JDISABLED');

Expand All @@ -78,14 +79,16 @@ public function templateStates()
/**
* Returns a published state on a grid
*
* @param integer $value The state value.
* @see HTMLHelperJGrid::state
*
* @param integer $i The row index
* @param boolean $enabled An optional setting for access control on the action.
* @param string $checkbox An optional prefix for checkboxes.
*
* @param integer $value The state value.
*
* @return string The Html code
*
* @see HTMLHelperJGrid::state
* @since 1.7.1
*/
public function state($value, $i, $enabled = true, $checkbox = 'cb')
Expand Down Expand Up @@ -139,17 +142,19 @@ public function state($value, $i, $enabled = true, $checkbox = 'cb')
* @param integer $state The state of the module (enabled, unenabled, trashed).
* @param string $selectedPosition The currently selected position for the module.
*
* @return string The necessary positions for the widget.
* @return array The necessary positions for the widget.
*
* @since 2.5
*
* @throws \Exception
*/
public function positions($clientId, $state = 1, $selectedPosition = '')
{
$templates = array_keys(ModulesHelper::getTemplates($clientId, $state));
$templateGroups = array();

// Add an empty value to be able to deselect a module position
$option = ModulesHelper::createOption('', Text::_('COM_MODULES_NONE'));
$option = ModulesHelper::createOption('', Text::_('COM_MODULES_NONE'));
$templateGroups[''] = ModulesHelper::createOptionGroup('', array($option));

// Add positions from templates
Expand All @@ -165,7 +170,7 @@ public function positions($clientId, $state = 1, $selectedPosition = '')
{
foreach ($positions as $position)
{
$text = ModulesHelper::getTranslatedModulePosition($clientId, $template, $position) . ' [' . $position . ']';
$text = ModulesHelper::getTranslatedModulePosition($clientId, $template, $position) . ' [' . $position . ']';
$options[] = ModulesHelper::createOption($position, $text);

if (!$isTemplatePosition && $selectedPosition === $position)
Expand All @@ -181,9 +186,11 @@ public function positions($clientId, $state = 1, $selectedPosition = '')
}

// Add custom position to options
$customGroupText = Text::_('COM_MODULES_CUSTOM_POSITION');
$editPositions = true;
$customPositions = ModulesHelper::getPositions($clientId, $editPositions);
$customGroupText = Text::_('COM_MODULES_CUSTOM_POSITION');
$editPositions = true;
$customPositions = ModulesHelper::getPositions($clientId, $editPositions);
$layoutBuilderPositions = ModulesHelper::getLayoutBuilderPositions($clientId);
$customPositions = array_merge($customPositions, $layoutBuilderPositions);

$app = Factory::getApplication();

Expand Down Expand Up @@ -247,7 +254,8 @@ public function positionList($clientId = 0)
}
catch (\RuntimeException $e)
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
Factory::getApplication()
->enqueueMessage($e->getMessage(), 'error');
}

// Pop the first item off the array if it's blank
Expand Down
20 changes: 10 additions & 10 deletions administrator/language/en-GB/lib_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -783,16 +783,16 @@ JLIB_PAGEBUILDER_COMPONENT="Component"
JLIB_PAGEBUILDER_CUSTOM="Custom"
JLIB_PAGEBUILDER_DELETE_COLUMN="Delete Column"
JLIB_PAGEBUILDER_DELETE_GRID="Delete Grid"
JLIB_PAGEBUILDER_DEVICE_LG="Devices with >= 992px"
JLIB_PAGEBUILDER_DEVICE_LG_SR_DESC="Create a layout for large devices with more than 992px"
JLIB_PAGEBUILDER_DEVICE_MD="Devices with >= 768px"
JLIB_PAGEBUILDER_DEVICE_MD_SR_DESC="Create a layout for medium sized devices with more than 768px"
JLIB_PAGEBUILDER_DEVICE_SM="Devices with >= 576px"
JLIB_PAGEBUILDER_DEVICE_SM_SR_DESC="Create a layout for small devices with more than 576px"
JLIB_PAGEBUILDER_DEVICE_XL="Devices with >= 1200px"
JLIB_PAGEBUILDER_DEVICE_XL_SR_DESC="Create a layout for very large devices with more than 1200px"
JLIB_PAGEBUILDER_DEVICE_XS="Devices with < 576px"
JLIB_PAGEBUILDER_DEVICE_XS_SR_DESC="Create a layout for very small devices with less than 576px"
JLIB_PAGEBUILDER_DEVICE_LG="Devices width >= 992px"
JLIB_PAGEBUILDER_DEVICE_LG_SR_DESC="Create a layout for large devices with a width more than 992px"
JLIB_PAGEBUILDER_DEVICE_MD="Devices width >= 768px"
JLIB_PAGEBUILDER_DEVICE_MD_SR_DESC="Create a layout for medium sized devices with a width more than 768px"
JLIB_PAGEBUILDER_DEVICE_SM="Devices width >= 576px"
JLIB_PAGEBUILDER_DEVICE_SM_SR_DESC="Create a layout for small devices with a width more than 576px"
JLIB_PAGEBUILDER_DEVICE_XL="Devices width >= 1200px"
JLIB_PAGEBUILDER_DEVICE_XL_SR_DESC="Create a layout for very large devices with a width more than 1200px"
JLIB_PAGEBUILDER_DEVICE_XS="Devices width < 576px"
JLIB_PAGEBUILDER_DEVICE_XS_SR_DESC="Create a layout for very small devices with a width less than 576px"
JLIB_PAGEBUILDER_EDIT_COLUMN="Edit Column"
JLIB_PAGEBUILDER_EDIT="Edit "
JLIB_PAGEBUILDER_EDIT_POSITION="Edit Module position"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<div>
<input :type="type" :id="id" :name="id" class="form-control" required
:placeholder="placeholder" v-model="content" @click="toggleSelection" />
<div id="inputselection_wrapper" v-if="show_list">
<span @click="select_item(custom_pos)" class="inputselection_list" v-for="custom_pos in options">{{custom_pos}}</span>
</div>

</div>
</template>

<script>
export default {
name: "input-selection",
props: ['placeholder', 'value', 'id', 'type', 'options'],
data() {
return {
show_list: false,
content: this.value
}
},
beforeDestroy() {
this.content = "";
this.$emit('input', "")
},
methods: {
select_item(payload){
this.content = payload;
this.toggleSelection();
},
toggleSelection(){
this.show_list = !this.show_list
}
},
watch:{
content(inew){
this.$emit('input', inew)
}

}
}
</script>

<style scoped>
#inputselection_wrapper {
max-width: 100%;
overflow-y: scroll;
overflow-x: hidden;
height: 150px;
border: 1px solid #cdcdcd;
}
.inputselection_list{
display: block;
padding: 8px 12px;
}
.inputselection_list:hover{
color: #fff;
background-color: #0d2538;
border-color: #0d2538;
}
</style>
Loading