2

I'm trying to find out how to force node to create only one node child of other type ?

I have 'hotel' node and i want to add one 'rooms' node and one 'facilities' node ('rooms' create 'room' and 'facilities' create 'facility')

by default when i will create hotel the system will create this 2 folders or to force him that he can create only one each

I prefer to do it with the management system (if possible) but code behind be good also !

Thanks in advance for all helpers!

Jarufi
  • 308
  • 1
  • 12

1 Answers1

1

As far as I am concerned, I do not know a way to achieve this by means of the Umbraco backoffice.

However, you can use the ContentService Events in order to cancel the creation of that particular page if it has been already created. The ContentServiceSaving method will fire up each time that you try to create a node in the CMS.

public class ContentServiceEventsController : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
      ContentService.Saving += ContentServiceSaving;
    }

    private void ContentServiceSaving(IContentService sender, SaveEventArgs<IContent> e)
    {

      switch (e.Entity.ContentType.Alias)
      {
        case "RoomsDocumentTypeAlias":
        case "FacilitiesDocumentTypeAlias":

        // Do your logic to detect if your Hotel node "Hilton eilat queen of sheba" 
        // already contains either a Rooms node or a Facilities node underneath.
        // If so, cancel the creation of the event of a new one.
        e.Cancel = true;
        break;

        default:
               break;
      }
    }
Felipe Cruz
  • 1,119
  • 10
  • 18