Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V15: Order children by sortorder #17898

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

Zeegaan
Copy link
Member

@Zeegaan Zeegaan commented Jan 6, 2025

Fixes #17844

Notes

  • Orders children by their sortorder.
  • This is only a feature for children, so does not apply to descendants/ancestors etc.

How to test

  • Create a doc type called child, with a property textstring called "Title"

  • Create a doc type called root, with allow as root set to true, and the "child" doc type allowed as child.

  • Create this structure in your content:

  • Root

    • Child One
    • Child Two
    • Child Three
    • Child four
  • Now swap the order, by clicking on root and selection the action "sort children"

  • You can then use a controller, or somewhere other, where you call the .Children on your root node,

  • I did this by creating a controller, and calling https://localhost:44339/test/index via postman

using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Web.UI;

[ApiController]
[Route("[controller]/[action]")]
public class TestController : Controller
{
    private readonly IPublishedContentCache _publishedContentCache;

    public TestController(IPublishedContentCache publishedContentCache)
    {
        _publishedContentCache = publishedContentCache;
    }

    [HttpGet]
    public async Task<IActionResult> Index()
    {
        var content = await _publishedContentCache.GetByIdAsync(new Guid("´{INSERT YOUR ROOT NODE KEY HERE}"));
        var children = content?.Descendants();
        return Ok(children?.Select(x => x.Name));
    }
}

@Zeegaan Zeegaan changed the base branch from contrib to v15/dev January 6, 2025 13:38
@Zeegaan Zeegaan changed the title Order by sortorder V15: Order children by sortorder Jan 6, 2025
Copy link
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@nikolajlauridsen nikolajlauridsen merged commit 5482f6b into v15/dev Jan 7, 2025
27 checks passed
@nikolajlauridsen nikolajlauridsen deleted the v15/bugfix/order-children-by-sortorder branch January 7, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Children() not returning items in the right order
2 participants