diff --git a/.github/README.md b/.github/README.md index dcb2530..2b5e372 100644 --- a/.github/README.md +++ b/.github/README.md @@ -14,6 +14,14 @@ Is your Backoffice a bit untidy? - Member Types - Data Types +## Installation + +### Install Package + +```powershell +dotnet add package Umbraco.Community.BackOfficeOrganiser +``` + ## Quick Start - Go to the backoffice diff --git a/docs/README_nuget.md b/docs/README_nuget.md index 7cb936b..05d79ff 100644 --- a/docs/README_nuget.md +++ b/docs/README_nuget.md @@ -15,6 +15,14 @@ Is your Backoffice a bit untidy? - Member Types - Data Types +## Installation + +### Install Package + +```powershell +dotnet add package Umbraco.Community.BackOfficeOrganiser +``` + ## Quick Start - Go to the backoffice diff --git a/docs/extending/index.md b/docs/extending/index.md new file mode 100644 index 0000000..8fefad3 --- /dev/null +++ b/docs/extending/index.md @@ -0,0 +1,59 @@ +## Extending + +You can implement your own `Organise Action`, a method that determines where a type should be moved to. Implement the following interfaces: + +- `Document Types` => `IContentTypeOrganiseAction` +- `Media Types` => `IMediaTypeOrganiseAction` +- `Member Types` => `IMemberTypeOrganiseAction` +- `Data Types` => `IDataTypeOrganiseAction` + +### Example +```csharp title="ExampleContentTypeOrganiseAction.cs" +using jcdcdev.Umbraco.Core.Extensions; +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Services; + +namespace Umbraco.Community.BackOfficeOrganiser.Organisers.ContentTypes; + +public class ExampleContentTypeOrganiseAction : IContentTypeOrganiseAction +{ + // Handle all but container types (Folders) + public bool CanMove(IContentType contentType, IContentTypeService contentTypeService) => !contentType.IsContainer; + + public void Move(IContentType contentType, IContentTypeService contentTypeService) + { + var folderId = -1; + var folderName = string.Empty; + var isComposition = contentTypeService.GetComposedOf(contentType.Id).Any(); + + if (contentType.AllowedTemplates?.Any() ?? false) + { + folderName = "Pages"; + } + else if (isComposition) + { + folderName = "Compositions"; + } + else if (contentType.IsElement) + { + folderName = "Element Types"; + } + + if (!folderName.IsNullOrWhiteSpace()) + { + folderId = contentTypeService.GetOrCreateFolder(folderName).Id; + } + + contentTypeService.Move(contentType, folderId); + } +} + +public class Composer : IComposer +{ + public void Compose(IUmbracoBuilder builder) + { + // Make sure you register your action BEFORE the default! + builder.ContentTypeOrganiseActions().Insert(); + } +} +``` \ No newline at end of file