private bool WebSupportsExtractNavigation(Web web)
        {
            bool isNavSupported = true;

            // The Navigation handler for managed metedata only works for sites with Publishing Features enabled
            if (!web.IsPublishingWeb())
            {
                // NOTE: Here we could have the same edge case of method WebSupportsProvisionNavigation.
                // Just as a reminder ...
                var navigationSettings = new WebNavigationSettings(web.Context, web);
                navigationSettings.EnsureProperties(ns => ns.CurrentNavigation, ns => ns.GlobalNavigation);
                if (navigationSettings.CurrentNavigation.Source == StandardNavigationSource.TaxonomyProvider)
                {
                    isNavSupported = false;
                }
                if (navigationSettings.GlobalNavigation.Source == StandardNavigationSource.TaxonomyProvider)
                {
                    isNavSupported = false;
                }
            }
            return(isNavSupported);
        }
        public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                GlobalNavigationType  globalNavigationType;
                CurrentNavigationType currentNavigationType;

                if (!WebSupportsExtractNavigation(web))
                {
                    scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Navigation_Context_web_is_not_publishing);
                    return(template);
                }

                // Retrieve the current web navigation settings
                var navigationSettings = new WebNavigationSettings(web.Context, web);
                navigationSettings.EnsureProperties(ns => ns.CurrentNavigation, ns => ns.GlobalNavigation);

                switch (navigationSettings.GlobalNavigation.Source)
                {
                case StandardNavigationSource.InheritFromParentWeb:
                    // Global Navigation is Inherited
                    globalNavigationType = GlobalNavigationType.Inherit;
                    break;

                case StandardNavigationSource.TaxonomyProvider:
                    // Global Navigation is Managed
                    globalNavigationType = GlobalNavigationType.Managed;
                    break;

                case StandardNavigationSource.PortalProvider:
                default:
                    // Global Navigation is Structural
                    globalNavigationType = GlobalNavigationType.Structural;
                    break;
                }

                switch (navigationSettings.CurrentNavigation.Source)
                {
                case StandardNavigationSource.InheritFromParentWeb:
                    // Current Navigation is Inherited
                    currentNavigationType = CurrentNavigationType.Inherit;
                    break;

                case StandardNavigationSource.TaxonomyProvider:
                    // Current Navigation is Managed
                    currentNavigationType = CurrentNavigationType.Managed;
                    break;

                case StandardNavigationSource.PortalProvider:
                default:
                    // Current Navigation is Structural
                    if (AreSiblingsEnabledForCurrentStructuralNavigation(web))
                    {
                        currentNavigationType = CurrentNavigationType.Structural;
                    }
                    else
                    {
                        currentNavigationType = CurrentNavigationType.StructuralLocal;
                    }
                    break;
                }

                template.Navigation = new Model.Navigation(
                    new GlobalNavigation(globalNavigationType,
                                         globalNavigationType == GlobalNavigationType.Structural ? GetGlobalStructuralNavigation(web, navigationSettings) : null,
                                         globalNavigationType == GlobalNavigationType.Managed ? GetGlobalManagedNavigation(web, navigationSettings) : null),
                    new CurrentNavigation(currentNavigationType,
                                          currentNavigationType == CurrentNavigationType.Structural | currentNavigationType == CurrentNavigationType.StructuralLocal ? GetCurrentStructuralNavigation(web, navigationSettings) : null,
                                          currentNavigationType == CurrentNavigationType.Managed ? GetCurrentManagedNavigation(web, navigationSettings) : null)
                    );
            }

            return(template);
        }
Exemple #3
0
        public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                GlobalNavigationType  globalNavigationType;
                CurrentNavigationType currentNavigationType;

                if (!WebSupportsExtractNavigation(web))
                {
                    scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Navigation_Context_web_is_not_publishing);
                    return(template);
                }

                // Retrieve the current web navigation settings
                var navigationSettings = new WebNavigationSettings(web.Context, web);
                navigationSettings.EnsureProperties(ns => ns.AddNewPagesToNavigation, ns => ns.CreateFriendlyUrlsForNewPages,
                                                    ns => ns.CurrentNavigation, ns => ns.GlobalNavigation);

                switch (navigationSettings.GlobalNavigation.Source)
                {
                case StandardNavigationSource.InheritFromParentWeb:
                    // Global Navigation is Inherited
                    globalNavigationType = GlobalNavigationType.Inherit;
                    break;

                case StandardNavigationSource.TaxonomyProvider:
                    // Global Navigation is Managed
                    globalNavigationType = GlobalNavigationType.Managed;
                    break;

                case StandardNavigationSource.PortalProvider:
                default:
                    // Global Navigation is Structural
                    globalNavigationType = GlobalNavigationType.Structural;
                    break;
                }

                switch (navigationSettings.CurrentNavigation.Source)
                {
                case StandardNavigationSource.InheritFromParentWeb:
                    // Current Navigation is Inherited
                    currentNavigationType = CurrentNavigationType.Inherit;
                    break;

                case StandardNavigationSource.TaxonomyProvider:
                    // Current Navigation is Managed
                    currentNavigationType = CurrentNavigationType.Managed;
                    break;

                case StandardNavigationSource.PortalProvider:
                default:
                    // Current Navigation is Structural
                    if (AreSiblingsEnabledForCurrentStructuralNavigation(web))
                    {
                        currentNavigationType = CurrentNavigationType.Structural;
                    }
                    else
                    {
                        currentNavigationType = CurrentNavigationType.StructuralLocal;
                    }
                    break;
                }

                var searchNavigation = GetStructuralNavigation(web, navigationSettings, Enums.NavigationType.SearchNav, template, creationInfo);
                var navigationEntity = new Model.Navigation(new GlobalNavigation(globalNavigationType,
                                                                                 globalNavigationType == GlobalNavigationType.Structural ? GetGlobalStructuralNavigation(web, navigationSettings, template, creationInfo) : null,
                                                                                 globalNavigationType == GlobalNavigationType.Managed ? GetGlobalManagedNavigation(web, navigationSettings, template, creationInfo) : null),
                                                            new CurrentNavigation(currentNavigationType,
                                                                                  currentNavigationType == CurrentNavigationType.Structural | currentNavigationType == CurrentNavigationType.StructuralLocal ? GetCurrentStructuralNavigation(web, navigationSettings, template, creationInfo) : null,
                                                                                  currentNavigationType == CurrentNavigationType.Managed ? GetCurrentManagedNavigation(web, navigationSettings, template, creationInfo) : null),
                                                            (searchNavigation != null && searchNavigation.NavigationNodes.Any()) ? searchNavigation : null);

                navigationEntity.AddNewPagesToNavigation       = navigationSettings.AddNewPagesToNavigation;
                navigationEntity.CreateFriendlyUrlsForNewPages = navigationSettings.CreateFriendlyUrlsForNewPages;

                // If a base template is specified then use that one to "cleanup" the generated template model
                if (creationInfo.BaseTemplate != null)
                {
                    if (!navigationEntity.Equals(creationInfo.BaseTemplate.Navigation))
                    {
                        template.Navigation = navigationEntity;
                    }
                }
                else
                {
                    template.Navigation = navigationEntity;
                }
            }

            return(template);
        }