Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Wouters 6 posts 96 karma points
    Mar 02, 2019 @ 13:23
    David Wouters
    0

    Methods missing from ContentService API

    Hi, I am new to Umbraco development, and I am stuck because GetContentOfContentType, GetDescendants, and many other documented ContentService methods are missing from the API. I have both installed from NuGet, and built from source. What am I doing wrong? TIA,

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Mar 02, 2019 @ 16:05
    Marc Goodson
    100

    Hi David

    Are you using v8 of Umbraco?

    This version has only just been released (this week), and it contains a large number of breaking changes from V7. Sadly not all of these are documented yet!

    This would explain why you aren't seeing the methods available on the ContentService that are documented as these have largely been renamed for V8.

    So I think you should be able to use:

     IEnumerable<IContent> GetPagedOfType(int contentTypeId, long pageIndex, int pageSize, out long totalRecords, IQuery<IContent> filter, Ordering ordering = null);
    

    and

      IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalRecords, IQuery<IContent> filter = null, Ordering ordering = null);
    

    There is also a 'count descendants' property:

        int CountDescendants(int parentId, string documentTypeAlias = null);
    

    regards

    Marc

  • David Wouters 6 posts 96 karma points
    Mar 02, 2019 @ 16:24
    David Wouters
    0

    Thanks Marc, yes it’s v8. I had already figured out some of the new methods (e.g. ContentTypeService.Get()), and I’d noticed the ones you mention, but as they are undocumented I’m not sure what they mean and what arguments to pass. But now I know I’m not overlooking something very obvious. I’ll see how far I can get without the doc.

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Mar 02, 2019 @ 17:14
    Marc Goodson
    0

    Hi David

    If your using Visual Studio, you can usually right click the Service

    eg Services.ContentService

    and select GoToDefinition you'll get from MetaData a list of the Services, then using the same trick with the interface eg right click IContentService or IContentTypeService, you'll get all their methods, and what parameters and types need to be passed to them.

    it's not documentation but at least you can see what's there!

    eg

    public interface IContentTypeService : IContentTypeBaseService<IContentType>, IContentTypeBaseService, IService
    {
        IEnumerable<string> GetAllContentTypeAliases(params Guid[] objectTypes);
        IEnumerable<int> GetAllContentTypeIds(string[] aliases);
        IEnumerable<string> GetAllPropertyTypeAliases();
    }
    

    If you want an explaination of the methods, you can look in the source code, where the comments are pretty good:

    https://github.com/umbraco/Umbraco-CMS/blob/91c52cffc8b7c70dc956f6c6610460be2d1adc51/src/Umbraco.Core/Services/Implement/ContentTypeService.cs

    the comments will be used to generate the auto-documentation pages - but I understand it's not quite ready to switch over to be the V8 docs yet.

    regards

    Marc

  • David Wouters 6 posts 96 karma points
    Mar 02, 2019 @ 17:44
    David Wouters
    0

    Really great Marc, that’s much more of an answer than I could have hoped for. And yes I’ve been able to use the new methods. Thanks again.

  • Tom 713 posts 954 karma points
    Aug 09, 2019 @ 02:36
    Tom
    0

    The GetPagedOfType is pretty annoying given sometimes you'd want to get all of them so does that mean it'd be perfectly ok to call it with int.MaxValue as your page size :)

Please Sign in or register to post replies

Write your reply to:

Draft