Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `#__menu_types` ADD COLUMN `ordering` int NOT NULL DEFAULT 0 AFTER `client_id`;
UPDATE `#__menu_types` SET `ordering` = `id` WHERE `client_id` = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "#__menu_types" ADD COLUMN "ordering" int NOT NULL DEFAULT 0 AFTER "client_id";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostgreSQL doesn't support "AFTER", so this will result in an SQL syntax error when updating on PostgreSQL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks can you fix it please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can take a while because I have to boot my environment and update my branches.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is #41177 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just see the update SQL scripts are also missing the ´/** CAN FAIL **/` installer hint. PR is in preparation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is #41184 .

UPDATE "#__menu_types" SET "ordering" = "id" WHERE "client_id" = 0;
2 changes: 2 additions & 0 deletions administrator/components/com_menus/forms/filter_menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
validate="options"
>
<option value="">JGLOBAL_SORT_BY</option>
<option value="a.ordering ASC">JGRID_HEADING_ORDERING_ASC</option>
<option value="a.ordering DESC">JGRID_HEADING_ORDERING_DESC</option>
<option value="a.title ASC">JGLOBAL_TITLE_ASC</option>
<option value="a.title DESC">JGLOBAL_TITLE_DESC</option>
<option value="a.id ASC">JGRID_HEADING_ID_ASC</option>
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_menus/presets/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
sql_where="a.client_id = 0"
sql_leftjoin="#__menu AS m ON m.menutype = a.menutype AND m.home = 1 LEFT JOIN #__languages AS l ON l.lang_code = m.language"
sql_group="a.id, a.title, a.menutype, m.language, l.lang_code"
sql_order="a.id DESC"
sql_order="a.ordering ASC"
>
<menuitem
title="{sql:title}"
Expand All @@ -162,7 +162,7 @@
sql_select="title, menutype"
sql_from="#__menu_types"
sql_where="client_id = 1"
sql_order="id DESC"
sql_order="ordering ASC"
>
<menuitem
title="{sql:title}"
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_menus/presets/menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
sql_where="a.client_id = 0"
sql_leftjoin="#__menu AS m ON m.menutype = a.menutype AND m.home = 1 LEFT JOIN #__languages AS l ON l.lang_code = m.language"
sql_group="a.id, a.title, a.menutype, m.language, l.lang_code"
sql_order="a.id DESC"
sql_order="a.ordering ASC"
sql_target="self"
>
<menuitem
Expand All @@ -64,7 +64,7 @@
sql_select="title, menutype"
sql_from="#__menu_types"
sql_where="client_id = 1"
sql_order="id DESC"
sql_order="ordering ASC"
sql_target="self"
>
<menuitem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Joomla\Component\Menus\Administrator\Controller;

use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Controller\AdminController;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -22,7 +22,7 @@
*
* @since 1.6
*/
class MenusController extends BaseController
class MenusController extends AdminController
{
/**
* Display the view
Expand Down
8 changes: 4 additions & 4 deletions administrator/components/com_menus/src/Model/MenuModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\MVC\Model\FormModel;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Table;
Expand All @@ -29,7 +29,7 @@
*
* @since 1.6
*/
class MenuModel extends FormModel
class MenuModel extends AdminModel
{
/**
* The prefix to use with controller messages.
Expand Down Expand Up @@ -295,10 +295,10 @@ public function save($data)
*
* @since 1.6
*/
public function delete($itemIds)
public function delete(&$pks)
{
// Sanitize the ids.
$itemIds = ArrayHelper::toInteger((array) $itemIds);
$itemIds = ArrayHelper::toInteger((array) $pks);

// Get a group row instance.
$table = $this->getTable();
Expand Down
4 changes: 3 additions & 1 deletion administrator/components/com_menus/src/Model/MenusModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct($config = [], MVCFactoryInterface $factory = null)
'title', 'a.title',
'menutype', 'a.menutype',
'client_id', 'a.client_id',
'ordering', 'a.ordering',
];
}

Expand Down Expand Up @@ -165,6 +166,7 @@ protected function getListQuery()
$db->quoteName('a.title'),
$db->quoteName('a.description'),
$db->quoteName('a.client_id'),
$db->quoteName('a.ordering'),
]
)
)
Expand Down Expand Up @@ -209,7 +211,7 @@ protected function getListQuery()
*
* @since 1.6
*/
protected function populateState($ordering = 'a.title', $direction = 'asc')
protected function populateState($ordering = 'a.ordering', $direction = 'asc')
{
$search = $this->getUserStateFromRequest($this->context . '.search', 'filter_search');
$this->setState('filter.search', $search);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class HtmlView extends BaseHtmlView
*/
public $activeFilters;

/**
* Ordering of the items
*
* @var array
* @since __DEPLOY_SINCE__
*/
protected $ordering;

/**
* Display the view
*
Expand Down
35 changes: 33 additions & 2 deletions administrator/components/com_menus/tmpl/menus/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Uri\Uri;

/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
Expand All @@ -36,6 +37,13 @@
}
}

$saveOrder = $listOrder == 'a.ordering';

if ($saveOrder) {
$saveOrderingUrl = 'index.php?option=com_menus&task=menus.saveOrderAjax&tmpl=component&' . Session::getFormToken() . '=1';
HTMLHelper::_('draggablelist.draggable');
}

$this->document->addScriptOptions('menus-default', ['items' => $itemIds]);
?>
<form action="<?php echo Route::_('index.php?option=com_menus&view=menus'); ?>" method="post" name="adminForm" id="adminForm">
Expand All @@ -60,6 +68,9 @@
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
</th>
<th scope="col">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
Expand Down Expand Up @@ -87,15 +98,35 @@
</th>
</tr>
</thead>
<tbody>
<tbody <?php if ($saveOrder) :
?> class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="<?php echo strtolower($listDirn); ?>" data-nested="false"<?php
endif; ?>>
<?php foreach ($this->items as $i => $item) :
$ordering = ($listOrder == 'a.ordering');
$canEdit = $user->authorise('core.edit', 'com_menus.menu.' . (int) $item->id);
$canManageItems = $user->authorise('core.manage', 'com_menus.menu.' . (int) $item->id);
$canChange = $user->authorise('core.edit.state', 'com_menus.menu.' . (int) $item->id);
?>
<tr class="row<?php echo $i % 2; ?>">
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="0">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
<td class="text-center d-none d-md-table-cell">
<?php
$iconClass = '';
if (!$canChange) {
$iconClass = ' inactive';
} elseif (!$saveOrder) {
$iconClass = ' inactive" title="' . Text::_('JORDERINGDISABLED');
}
?>
<span class="sortable-handler<?php echo $iconClass; ?>">
<span class="icon-ellipsis-v" aria-hidden="true"></span>
</span>
<?php if ($canChange && $saveOrder) : ?>
<input type="text" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
<?php endif; ?>
</td>
<th scope="row">
<div class="name break-word">
<?php if ($canEdit) : ?>
Expand Down
5 changes: 3 additions & 2 deletions installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ CREATE TABLE IF NOT EXISTS `#__menu_types` (
`title` varchar(48) NOT NULL,
`description` varchar(255) NOT NULL DEFAULT '',
`client_id` int NOT NULL DEFAULT 0,
`ordering` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_menutype` (`menutype`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
Expand All @@ -560,8 +561,8 @@ CREATE TABLE IF NOT EXISTS `#__menu_types` (
-- Dumping data for table `#__menu_types`
--

INSERT IGNORE INTO `#__menu_types` (`id`, `asset_id`, `menutype`, `title`, `description`, `client_id`) VALUES
(1, 0, 'mainmenu', 'Main Menu', 'The main menu for the site', 0);
INSERT IGNORE INTO `#__menu_types` (`id`, `asset_id`, `menutype`, `title`, `description`, `client_id`, `ordering`) VALUES
(1, 0, 'mainmenu', 'Main Menu', 'The main menu for the site', 0, 1);

-- --------------------------------------------------------

Expand Down
5 changes: 3 additions & 2 deletions installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ CREATE TABLE IF NOT EXISTS "#__menu_types" (
"title" varchar(48) NOT NULL,
"description" varchar(255) DEFAULT '' NOT NULL,
"client_id" int DEFAULT 0 NOT NULL,
"ordering" int NOT NULL DEFAULT 0,
PRIMARY KEY ("id"),
CONSTRAINT "#__menu_types_idx_menutype" UNIQUE ("menutype")
);
Expand All @@ -584,8 +585,8 @@ CREATE TABLE IF NOT EXISTS "#__menu_types" (
-- Dumping data for table `#__menu_types`
--

INSERT INTO "#__menu_types" ("id", "asset_id", "menutype", "title", "description", "client_id") VALUES
(1, 0, 'mainmenu', 'Main Menu', 'The main menu for the site', 0);
INSERT INTO "#__menu_types" ("id", "asset_id", "menutype", "title", "description", "client_id", "ordering") VALUES
(1, 0, 'mainmenu', 'Main Menu', 'The main menu for the site', 0, 1);

SELECT setval('#__menu_types_id_seq', 2, false);

Expand Down