[5.2] Add the function to order the categories
Pull Request for Issue #39532 .
Summary of Changes
- Create a field to set the ordering of the categories in the backend.
- Add the functionality to order the categories according to the order by query in the database: To determine the ordering for the database query, include the getCategoryOrdering method. The desired category ordering preference is fetched in the getChildrenCategories method, a SQL query is built based on this preference, and the resulting order is used to sort and restructuring the array of child categories. The resulting array $orderedChildrenCategories will contain the children categories sorted as per the Joomla database query order.
Testing Instructions
- Create different categories and assign them a parent category. (Menu -> Content-> Categories -> New)
- Move to site modules and add Articles Categories Module (New -> Articles Categories +). Select Parent Category and find the option for Category Ordering just below it and set according to your choice.
- Save the module.
Actual result BEFORE applying this Pull Request
No option to order the categories.
Expected result AFTER applying this Pull Request
You are able to order the categories according to their title and lft values.
https://github.com/joomla/joomla-cms/assets/121369234/89b42954-8bc8-4a4c-b0e0-b21057c468a1
Link to documentations
Please select:
- [ ] Documentation link for docs.joomla.org:
- [x] No documentation changes for docs.joomla.org needed
- [ ] Pull Request link for manual.joomla.org:
- [x] No documentation changes for manual.joomla.org needed
thanks for your pull request, but I think that sorting should be in the categories service and not in the module helper. Also the target branch should be 5.0. @laoneo what do you think?
Hi, @HLeithner thank you for taking the time to review my pull request. I'll wait for your confirmation on the services part since I don't know it well. In the meantime, I've updated the branch to 5.0 as you recommended. Please let me know how you'd like to proceed.
I have tested this item :white_check_mark: successfully on 33d9d66469365f5efb47796de5a32879c8ea3202
Tested on Joomla 4.4 with PHP 8.1.22
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41336.
I have tested this item :white_check_mark: successfully on 453d1dd8698797ce990047c2d5ac7e8e588afb2c
Tested on 5.0.0-beta2-dev - it works as described and makes sense to have Categories in Alpha order. No comment on whether this is the right place for this feature.
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41336.
@HLeithner As you moved this PR to draft: Shall we reopen the issue #39532 ?
I change it to draft so it's not merged by accident, I'm not happy with the solution but I think it can be improved. In addition I don't have the time to do this before 5.0.0 release I want to postpone it to maybe 5.1
This pull request has been automatically rebased to 5.1-dev.
I have tested this item :white_check_mark: successfully on 453d1dd8698797ce990047c2d5ac7e8e588afb2c
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41336.
This pull request has been automatically rebased to 5.2-dev.
As Joomla 5.2 will have the new articles module that offers this functionality (and more) shouldnt we just close this and leave this module as it is