Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

available Blocks restrictable with BlockItemTypeAttribute for Content… #1889

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/Piranha.AttributeBuilder/ContentTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private ContentType GetContentType(Type type)
throw new ArgumentException($"[{ type.Name }] Id and Title is mandatory for content types.");
}

return new ContentType
var contentType= new ContentType
{
Id = attr.Id,
CLRType = type.GetTypeInfo().AssemblyQualifiedName,
Expand All @@ -326,6 +326,14 @@ private ContentType GetContentType(Type type)
CustomEditors = GetEditors(type),
Regions = GetRegions(type)
};
// Add block types
var blockTypes = type.GetCustomAttributes<BlockItemTypeAttribute>();
foreach (var blockType in blockTypes)
{
contentType.BlockItemTypes.Add(blockType.Type.FullName);
}

return contentType;
}
return null;
}
Expand Down
14 changes: 14 additions & 0 deletions core/Piranha.Manager/Controllers/ContentApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ public BlockListModel GetBlockTypesForPost(string postType, string parentType =
return _contentType.GetPostBlockTypes(postType, parentType);
}

/// <summary>
/// Gets the currently available block types for the
/// specified content type.
/// </summary>
/// <param name="contentType">The content type id</param>
/// <param name="parentType">The optional parent group type</param>
/// <returns>The block list model</returns>
[Route("blocktypes/content/{contentType}/{parentType?}")]
[HttpGet]
public BlockListModel GetBlockTypesForContentType(string contentType, string parentType = null)
{
return _contentType.GetContentTypeBlockTypes(contentType, parentType);
}

/// <summary>
/// Gets the currently available block types.
/// </summary>
Expand Down
26 changes: 26 additions & 0 deletions core/Piranha.Manager/Services/ContentTypeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@ public BlockListModel GetPostBlockTypes(string postType, string parentType = nul
return model;
}

/// <summary>
/// Gets the currently available block types for the
/// specified content type.
/// </summary>
/// <param name="contentType">The content type id</param>
/// <param name="parentType">The optional parent group type</param>
/// <returns>The block list model</returns>
public BlockListModel GetContentTypeBlockTypes(string contentType, string parentType = null)
{
var type = App.ContentTypes.GetById(contentType);
var model = GetBlockTypes(parentType);

if (type != null && type.BlockItemTypes.Count > 0)
{
// First remove all block types that are not allowed
foreach (var category in model.Categories)
{
category.Items = category.Items.Where(i => type.BlockItemTypes.Contains(i.Type)).ToList();
}

// Secondly remove all empty categories
model.Categories = model.Categories.Where(c => c.Items.Count > 0).ToList();
}
return model;
}

/// <summary>
/// Gets the currently available block types.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions core/Piranha.Manager/assets/dist/css/full.min.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions core/Piranha.Manager/assets/dist/css/full.rtl.min.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions core/Piranha.Manager/assets/dist/css/slim.min.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions core/Piranha.Manager/assets/dist/css/slim.rtl.min.css

Large diffs are not rendered by default.

Loading