-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from jcdcdev/dev/v10
10.1.0
- Loading branch information
Showing
16 changed files
with
284 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...Umbraco.Community.BackOfficeOrganiser/Composing/BackofficeOrganiserNotificationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Microsoft.Extensions.Options; | ||
using Umbraco.Cms.Core.Events; | ||
using Umbraco.Cms.Core.Notifications; | ||
using Umbraco.Community.BackOfficeOrganiser.Models; | ||
using Umbraco.Community.BackOfficeOrganiser.Organisers.ContentTypes; | ||
using Umbraco.Community.BackOfficeOrganiser.Organisers.DataTypes; | ||
using Umbraco.Community.BackOfficeOrganiser.Organisers.MediaTypes; | ||
using Umbraco.Community.BackOfficeOrganiser.Organisers.MemberTypes; | ||
|
||
namespace Umbraco.Community.BackOfficeOrganiser.Composing; | ||
|
||
public class BackofficeOrganiserNotificationHandler : | ||
INotificationHandler<DataTypeSavedNotification>, | ||
INotificationHandler<ContentTypeSavedNotification>, | ||
INotificationHandler<MemberTypeSavedNotification>, | ||
INotificationHandler<MediaTypeSavedNotification> | ||
{ | ||
private readonly ContentTypeOrganiser _contentTypeOrganiser; | ||
private readonly DataTypeOrganiser _dataTypeOrganiser; | ||
private readonly MediaTypeOrganiser _mediaTypeOrganiser; | ||
private readonly MemberTypeOrganiser _memberTypeOrganiser; | ||
private readonly BackOfficeOrganiserOptions _options; | ||
|
||
public BackofficeOrganiserNotificationHandler( | ||
DataTypeOrganiser dataTypeOrganiser, | ||
ContentTypeOrganiser contentTypeOrganiser, | ||
MediaTypeOrganiser mediaTypeOrganiser, | ||
MemberTypeOrganiser memberTypeOrganiser, | ||
IOptions<BackOfficeOrganiserOptions> options) | ||
{ | ||
_dataTypeOrganiser = dataTypeOrganiser; | ||
_contentTypeOrganiser = contentTypeOrganiser; | ||
_mediaTypeOrganiser = mediaTypeOrganiser; | ||
_memberTypeOrganiser = memberTypeOrganiser; | ||
_options = options.Value; | ||
} | ||
|
||
public void Handle(ContentTypeSavedNotification notification) | ||
{ | ||
if (!_options.ContentTypes.OrganiseOnSave) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var item in notification.SavedEntities) | ||
{ | ||
_contentTypeOrganiser.Organise(item); | ||
} | ||
} | ||
|
||
public void Handle(DataTypeSavedNotification notification) | ||
{ | ||
if (!_options.DataTypes.OrganiseOnSave) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var dataType in notification.SavedEntities) | ||
{ | ||
_dataTypeOrganiser.Organise(dataType); | ||
} | ||
} | ||
|
||
public void Handle(MediaTypeSavedNotification notification) | ||
{ | ||
if (!_options.MediaTypes.OrganiseOnSave) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var item in notification.SavedEntities) | ||
{ | ||
_mediaTypeOrganiser.Organise(item); | ||
} | ||
} | ||
|
||
public void Handle(MemberTypeSavedNotification notification) | ||
{ | ||
if (!_options.MemberTypes.OrganiseOnSave) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var item in notification.SavedEntities) | ||
{ | ||
_memberTypeOrganiser.Organise(item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Umbraco.Community.BackOfficeOrganiser/Models/ContentTypeOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Umbraco.Community.BackOfficeOrganiser.Models; | ||
|
||
public class ContentTypeOptions | ||
{ | ||
public bool OrganiseOnSave { get; set; } = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Umbraco.Community.BackOfficeOrganiser/Models/MediaTypeOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Umbraco.Community.BackOfficeOrganiser.Models; | ||
|
||
public class MediaTypeOptions | ||
{ | ||
public bool OrganiseOnSave { get; set; } = true; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Umbraco.Community.BackOfficeOrganiser/Models/MemberTypeOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Umbraco.Community.BackOfficeOrganiser.Models; | ||
|
||
public class MemberTypeOptions | ||
{ | ||
public bool OrganiseOnSave { get; set; } = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/Umbraco.Community.BackOfficeOrganiser/Organisers/ContentTypes/ElementTypeOrganiser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using jcdcdev.Umbraco.Core.Extensions; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.PropertyEditors; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Extensions; | ||
|
||
namespace Umbraco.Community.BackOfficeOrganiser.Organisers.ContentTypes; | ||
|
||
public class ElementTypeOrganiser : IContentTypeOrganiseAction | ||
{ | ||
private readonly IDataTypeService _dataTypeService; | ||
|
||
public ElementTypeOrganiser(IDataTypeService dataTypeService) | ||
{ | ||
_dataTypeService = dataTypeService; | ||
} | ||
|
||
public bool CanMove(IContentType contentType, IContentTypeService contentTypeService) => contentType.IsElement; | ||
|
||
public void Move(IContentType contentType, IContentTypeService contentTypeService) | ||
{ | ||
var nestedContentDataTypes = _dataTypeService.GetByEditorAlias(Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.NestedContent).Select(x => x.ConfigurationAs<NestedContentConfiguration>()); | ||
var blockGridDataTypes = _dataTypeService.GetByEditorAlias(Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.BlockGrid).Select(x => x.ConfigurationAs<BlockGridConfiguration>()); | ||
var blockListDataTypes = _dataTypeService.GetByEditorAlias(Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.BlockList).Select(x => x.ConfigurationAs<BlockListConfiguration>()); | ||
|
||
var nestedContentContentTypeAliases = new List<string>(); | ||
var gridContentTypeKeys = new List<Guid>(); | ||
var blockContentTypeKeys = new List<Guid>(); | ||
foreach (var blockGridDataType in blockGridDataTypes) | ||
{ | ||
foreach (var blockGrid in blockGridDataType?.Blocks ?? Array.Empty<BlockGridConfiguration.BlockGridBlockConfiguration>()) | ||
{ | ||
gridContentTypeKeys.Add(blockGrid.ContentElementTypeKey); | ||
if (blockGrid.SettingsElementTypeKey.HasValue) | ||
{ | ||
gridContentTypeKeys.Add(blockGrid.SettingsElementTypeKey.Value); | ||
} | ||
} | ||
} | ||
|
||
foreach (var blockListDataType in blockListDataTypes) | ||
{ | ||
foreach (var blockList in blockListDataType?.Blocks ?? Array.Empty<BlockListConfiguration.BlockConfiguration>()) | ||
{ | ||
blockContentTypeKeys.Add(blockList.ContentElementTypeKey); | ||
if (blockList.SettingsElementTypeKey.HasValue) | ||
{ | ||
blockContentTypeKeys.Add(blockList.SettingsElementTypeKey.Value); | ||
} | ||
} | ||
} | ||
|
||
foreach (var nestedContentDataType in nestedContentDataTypes) | ||
{ | ||
if (nestedContentDataType == null) | ||
{ | ||
continue; | ||
} | ||
|
||
var aliases = nestedContentDataType.ContentTypes?.Select(x => x.Alias).WhereNotNull() ?? Array.Empty<string>(); | ||
nestedContentContentTypeAliases.AddRange(aliases); | ||
} | ||
|
||
var isNestedContent = nestedContentContentTypeAliases.Contains(contentType.Alias); | ||
var isBlockGrid = gridContentTypeKeys.Contains(contentType.Key); | ||
var isBlockList = blockContentTypeKeys.Contains(contentType.Key); | ||
|
||
var parent = contentTypeService.GetOrCreateFolder("Element Types"); | ||
var folderName = string.Empty; | ||
if (isNestedContent && !isBlockGrid && !isBlockList) | ||
{ | ||
folderName = "Nested Content"; | ||
} | ||
else if (isBlockGrid && !isNestedContent && !isBlockList) | ||
{ | ||
folderName = "Block Grid"; | ||
} | ||
else if (isBlockList && !isNestedContent && !isBlockGrid) | ||
{ | ||
folderName = "Block List"; | ||
} | ||
|
||
if (!string.IsNullOrWhiteSpace(folderName)) | ||
{ | ||
parent = contentTypeService.GetOrCreateFolder(folderName, parent.Id); | ||
} | ||
|
||
contentTypeService.Move(contentType, parent.Id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.