Skip to content

Commit

Permalink
Split composers that add views if people only use the core package (#224
Browse files Browse the repository at this point in the history
)
  • Loading branch information
patrickdemooij9 authored Aug 20, 2023
1 parent d8d9c11 commit 8d99c92
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using SeoToolkit.Umbraco.Common.Core.Collections;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Membership;
Expand All @@ -7,11 +9,23 @@ namespace SeoToolkit.Umbraco.Common.Core.ContentApps
{
public class SeoSettingsContentAppFactory : IContentAppFactory
{
private readonly IServiceScopeFactory _serviceScopeFactory;

public SeoSettingsContentAppFactory(IServiceScopeFactory serviceScopeFactory)
{
_serviceScopeFactory = serviceScopeFactory;
}

public ContentApp GetContentAppFor(object source, IEnumerable<IReadOnlyUserGroup> userGroups)
{
if (source is not IContentType)
return null;

using var scope = _serviceScopeFactory.CreateScope();

var displayProviders = scope.ServiceProvider.GetService<DisplayCollection>();
if (displayProviders is null || displayProviders.Count == 0) return null;

return new ContentApp
{
Name = "SEO",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,6 @@ public void Compose(IUmbracoBuilder builder)
builder.WithCollectionBuilder<FieldProviderCollectionBuilder>()
.Add<InheritedValueFieldProvider>()
.Add<PageNameFieldProvider>();

if (!disabledModules.Contains(DisabledModuleConstant.DocumentTypeContextApp))
{
builder.WithCollectionBuilder<DisplayCollectionBuilder>()
.Add<MetaFieldsDocumentSettingsDisplayProvider>();

builder.WithCollectionBuilder<SeoDisplayCollectionBuilder>()
.Add<MetaFieldsContentDisplayProvider>();

builder.WithCollectionBuilder<SeoGroupCollectionBuilder>()
.Append<MetaFieldsGroup>()
.Append<OpenGraphFieldsGroup>()
.Append<OthersFieldGroup>();
}
}
}
}
38 changes: 38 additions & 0 deletions src/SeoToolkit.Umbraco.MetaFields/Composer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.Extensions.Configuration;
using SeoToolkit.Umbraco.Common.Core.Collections;
using SeoToolkit.Umbraco.Common.Core.Constants;
using SeoToolkit.Umbraco.MetaFields.Core.Collections;
using SeoToolkit.Umbraco.MetaFields.Core.Common.DisplayProviders;
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldGroups;
using SeoToolkit.Umbraco.MetaFields.Core.Config.Models;
using System;
using System.Linq;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;

namespace SeoToolkit.Umbraco.MetaFields
{
internal class Composer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
var section = builder.Config.GetSection("SeoToolkit:MetaFields");
var settings = section?.Get<MetaFieldsAppSettingsModel>();
var disabledModules = settings?.DisabledModules ?? Array.Empty<string>();

if (!disabledModules.Contains(DisabledModuleConstant.DocumentTypeContextApp))
{
builder.WithCollectionBuilder<DisplayCollectionBuilder>()
.Add<MetaFieldsDocumentSettingsDisplayProvider>();

builder.WithCollectionBuilder<SeoDisplayCollectionBuilder>()
.Add<MetaFieldsContentDisplayProvider>();

builder.WithCollectionBuilder<SeoGroupCollectionBuilder>()
.Append<MetaFieldsGroup>()
.Append<OpenGraphFieldsGroup>()
.Append<OthersFieldGroup>();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ public void Compose(IUmbracoBuilder builder)

builder.Components().Append<EnableModuleComponent>();

if (!disabledModules.Contains(DisabledModuleConstant.DocumentTypeContextApp))
{
builder.WithCollectionBuilder<DisplayCollectionBuilder>()
.Add<SitemapDocumentTypeDisplayProvider>();
}

builder.Services.AddScoped<ISitemapGenerator, SitemapGenerator>();
builder.Services.AddScoped<ISitemapIndexGenerator, SitemapIndexGenerator>();
builder.Services.AddUnique<ISitemapService, SitemapService>();
Expand Down
27 changes: 27 additions & 0 deletions src/SeoToolkit.Umbraco.Sitemap/Composer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Configuration;
using SeoToolkit.Umbraco.Common.Core.Collections;
using SeoToolkit.Umbraco.Common.Core.Constants;
using SeoToolkit.Umbraco.Sitemap.Core.Common.DisplayProviders;
using SeoToolkit.Umbraco.Sitemap.Core.Config.Models;
using System;
using System.Linq;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;

namespace SeoToolkit.Umbraco.Sitemap
{
internal class Composer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
var section = builder.Config.GetSection("SeoToolkit:Sitemap");
var disabledModules = section?.Get<SitemapAppSettingsModel>()?.DisabledModules ?? Array.Empty<string>();

if (!disabledModules.Contains(DisabledModuleConstant.DocumentTypeContextApp))
{
builder.WithCollectionBuilder<DisplayCollectionBuilder>()
.Add<SitemapDocumentTypeDisplayProvider>();
}
}
}
}

0 comments on commit 8d99c92

Please sign in to comment.