Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:55:17+00:00 2026-06-09T10:55:17+00:00

I’m sure this must have been asked before. but I’ve been unable to find

  • 0

I’m sure this must have been asked before. but I’ve been unable to find anything helpful.

I want to create some widgets (existing widget types, a menu, a projection), as part of a custom module install. aslo some queries and Projection pages.

as well as a new menu (orchard 1.5.1), I figured out the menu part form the code in the setup module

…

    // create a project menu
    var projectMenu = _menuService.Create("new Menu");

    // assign the project items to all current menu items
    foreach (var menuItem in _menuService.Get().Where(x => x.ContentItem.ContentType == "Project"))
    {
        // if they don't have a position or a text, then they are not displayed
        if (string.IsNullOrWhiteSpace(menuItem.MenuPosition) || string.IsNullOrEmpty(menuItem.MenuText))
    {
       continue;
    }
    menuItem.Menu = projectMenu.ContentItem;

Can I include something in my migration to add the widgets and projections ?

I’ve been looking at the Orchard Recipe module, and see there is code there for executing commands to set up widgets. But I’m not sure how best to tap into this…

Creating an instance of recipe manages and executing a whole recipe seem a bit convoluted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:55:20+00:00Added an answer on June 9, 2026 at 10:55 am

    There are some quite useful seemingly undocumented services all over the place you can use.

    With the following constructor

    public class MigrationProjectType : DataMigrationImpl 
        {
            private readonly IMenuService _menuService;
            private readonly IContentManager _contentManager;
            private readonly IQueryService _queryService;
            private readonly IWidgetsService _widgetsService;
    
            public MigrationProjectType(IMenuService menuService, IContentManager contentManager,  IQueryService queryService, IWidgetsService widgetsService)
            {
                _menuService = menuService;
                _contentManager = contentManager;
                _queryService = queryService;
                _widgetsService = widgetsService;
            }
    ...
    }
    

    Auto fac will take care of instantiating the services

    then

    public int UpdateFrom2()
            {
                // create a project menu
                var projectMenu = _menuService.Create("Projects Menu");
    
                // assign the project items to all current menu items
                foreach (var menuItem in _menuService.Get().Where(x => x.ContentItem.ContentType == "Project"))
                {
                    // if they don't have a position or a text, then they are not displayed
                    if (string.IsNullOrWhiteSpace(menuItem.MenuPosition) || string.IsNullOrEmpty(menuItem.MenuText))
                    {
                        continue;
                    }
                    menuItem.Menu = projectMenu.ContentItem;
                }
    
                // create layer part 
                _widgetsService.CreateLayer("SideBar", "desc", "url(\"~\")");
    
                var defaultLayer = _widgetsService.GetLayers().First(x => x.Name == "Default");
    
                var widget =  _widgetsService.CreateWidget(defaultLayer.Id, "MenuWidget", "Projects Menu", "2", "Navigation");
    
                var menuWidget = widget.As<MenuWidgetPart>();
                menuWidget.Record.Menu = projectMenu.ContentItem.Record;
    
                _contentManager.Publish(menuWidget.ContentItem);
    
                return 3;
            }
    

    there is a similar service for Queries, but I’m stil not sure how to add filters to queries, for projections…

    UPDATE

    heres how you can add a query and filter

    public int UpdateFrom7()
            {
    
    
                // create a project menu
                var projectMenu = _queryService.CreateQuery("My projects 3");
    
                var form = new Form { ContentTypes = "Project" };
                var xmlSerializer = new XmlSerializer(form.GetType());
                StringWriter sww = new StringWriter();
                XmlWriter writer = XmlWriter.Create(sww);
                xmlSerializer.Serialize(writer, form);
                var state = sww.ToString();
    
    
                projectMenu.FilterGroups[0].Filters.Add(new FilterRecord
                {
                    Category = "Content",
                    Description = "My filter",
                    Position = 0,
                    State = state,
                    Type = "ContentTypes"
                });
    
                _contentManager.Publish(projectMenu.ContentItem);
    
    
                return 8;
            }
    
    [Serializable]
        public class Form
        {
            public string Description { get; set; }
            public string ContentTypes { get; set; }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have been unable to fix a problem with Java Unicode and encoding. The
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.